Try to do the same in C, you'll find that sometimes (depends on platform/compiler) result may not be exact in floating point operations. This is considered to be normal, since CPU/FPU's real axis is not precise. Actually, no double mathematics can be treated as 'precise' unless we know the error of each operation and correct them averagely. Anyway, we should always suggest the result is erroneus.
------------------ With best of best regards, Pawel S. Veselov ( aka Black Angel )
With best of best regards, Pawel S. Veselov ( aka Black Angel )
This was the lesson. I think it is covered in the book. It's the trade off for floating point. Integers are very accurate, but have some limitations. Floats can handle huge numbers and decimal values but have only 7 (float) or 14 (double) significant digits of accuracy. This is why after doing a bit of floating point math, you don't want to test if something is 0: It might be a hair off and your test might fail.