Here's a short explanation of what happens.
Recall that when a ratio of integers (a rational number) is shown in decimal form, the decimal fraction terminates only if the integers have denominator has no factors but 2 and 5. Thus one-eighth == 0.125 and two-fifths == 0.4, but one-third == 0.33333333.... and one-seventh == 0.142857142857.... .
The same thing happens with n-al fractions in any base n. Processors represent floats in base two, so any rational fraction with a factor of 5 forms an infinite repeating pattern of ones and zeros. The processor can only hold a finite number of the leading bits, so the floating point representation of 182/5 == 36.2, 183/5 == 36.4, and 1/5 == 0.2 are all low-side approximations. When they are added and subtracted, the results are internally rounded from a few extra bits the processor keeps hidden, with the confounding result that floating-point addition is not even associative!
After Compline,
Zaxo
In reply to [Why] Re: float values and operators
by Zaxo
in thread float values and operators
by soulchild
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |