Floating point bug?

Zentrader zentraders at gmail.com
Fri Feb 15 13:55:47 EST 2008


I disagree with this statement
<quote>But that doesn't change the fact that it will expose the same
rounding-errors as floats do - just for different numbers. </quote>
The example used has no rounding errors.  For anything less that 28
significant digits it rounds to 1.0.  With floats 1.0/3 yields
0.33333333333333331<-- on my machine.  Also you can compare two
decimal.Decimal() objects for equality.  With floats you have to test
for a difference less than some small value.  BTW, a college professor
who also wrote code for a living made this offhand remark "In general
it is best to multiply first and then divide."  Good general advice.



More information about the Python-list mailing list