Possible Duplicate:
Why “for( i = 0.1 ; i != 1.0 ; i += 0.1)” doesn’t break at i = 1.0?
I have a numeric (real) interval [x, y]. I must iterate through it using something like:
nr = 0;
for (i = x; i <= y; i += step) //step is a small double value
nr++;
For [-1, 1] with 0.001 step, it is clear nr should be 2001 (-1.000 … 0.999 1.000), however it computes nr = 2000 (I investigated and it fails the last comparison: 0.999 + 0.001 > 1.000)
How can I compute the exact nr value?
1 Answer