kokkos/kokkos-tutorials

integer division issue in slide 19 ?

aminiussi opened this issue · 1 comments

Just an insignificant detail I'm sure but in the short version of the slides, slide 19/83:

double  totalIntegral = 0;
for (int64_t i = 0; i < numberOfIntervals; ++i) {
  const  double x =lower+ (i/numberOfIntervals) * (upper-lower);
  const  double  thisIntervalsContribution =function(x);
  totalIntegral  +=  thisIntervalsContribution;
}
totalIntegral  *= dx;

assuming numberOfIntervals is of int type, isn't i/numberOfIntervals always 0 ?

You are correct, it should be const double x =lower+ ((double)i/numberOfIntervals) * (upper-lower);