4 ms·
That's just how floating point math works in every language. Python intro: http://docs.python.org/tutorial/floatingpoint.html http://docs.python.org/tutorial/fl
by Erwin 17y ago
That's just how floating point math works in every language. Python intro: http://docs.python.org/tutorial/floatingpoint.html http://docs.python.org/tutorial/floatingpoint.html
Comprehensive paper going into depth about many other issues: http://docs.sun.com/source/806-3568/ncg_goldberg.html http://docs.sun.com/source/806-3568/ncg_goldberg.html
If you don't understand the above, your missiles may kill you and your rockets may explode: http://www.ima.umn.edu/~arnold/455.f96/disasters.html http://www.ima.umn.edu/~arnold/455.f96/disasters.html
However if you don't care about performance but want precision, you can use e.g. the Decimal module (which is a little annoying with syntax help from the compiler) or perhaps various wrappers for arbitrary precision libraries that are around.
- bluetech 17y agoWhat about this: http://docs.python.org/dev/py3k/whatsnew/3.1.html#other-language-changes http://docs.python.org/dev/py3k/whatsnew/3.1.html#other-lang... (the fifth bullet) It seems to make things more reasonable. After all, Python has showed that saying "that just how it works" can be avoided, as in the case of / defaulting to floating-point division.