I have a simple C++ program compiled using gcc 4.2.4 on 32-bit Ubuntu 8.04. It has a for-loop in which a double variable is incremented from zero t
You should not use == or <= for doubles due to its internal representation. On last step you'll get 0.95000000000000029. Instead you could use the following code:
stepSize = 0.05;
// stepSize/2 looks like a good delta for most cases
for (double index = rangeMin; index < rangeMax+stepSize/2; index+= stepSize)
{
cout << index << endl;
}
For more details read What Every Computer Scientist Should Know About Floating-Point Arithmetic.