Floating point errors?
tim.one at home.com
Fri May 11 03:39:57 CEST 2001
> int( (2.3 - 2) * 1000 ) = 299
> int( .3 * 1000 ) = 300
> What am I missing? The first one seems too simple to expect a rounding
> error :)
[Erik Max Francis]
> Floating point values are not exact.
Harrumph. Of course they're exact! Selling them as some sort of fuzzy
mystery is what keeps people confused about them 50 years after they should
have learned better.
> >>> 2.3 - 2.0
And on an IEEE-754 machine, that's the rounded *display* of an exact number,
OTOH, the 754 double closest to 0.3 is exactly
Now I'm sure Ben feels confident about his numeric future <wink>.
in-base-2-ly y'rs - tim
More information about the Python-list