kokkos / kokkos-tutorials

Tutorials for the Kokkos C++ Performance Portability Programming Ecosystem
Other
286 stars 96 forks source link

integer division issue in slide 19 ? #54

Closed aminiussi closed 3 years ago

aminiussi commented 3 years ago

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 ?

dalg24 commented 3 years ago

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