[issue7704] Math calculation problem (1.6-1.0)>0.6, python said TRUE
Tim Peters
report at bugs.python.org
Thu Jan 14 23:37:42 CET 2010
Tim Peters <tim.peters at gmail.com> added the comment:
You can use the comparison, provided you understand what it does, and that it does NOT do what you hoped it would do. Here:
>>> 1.6 - 1.0
0.60000000000000009
That shows quite clearly that subtracting 1 from the binary approximation to 1.6 does not leave exactly 0.6. If you need that to happen, use the decimal module (which, in return for being slower, emulates decimal floating-point arithmetic).
Your other case (8.6-8.0) does NOT equal (decimal) 0.6 exactly either, but fools you into thinking it's working the way you hope it works because the result is a little /less/ than 0.6:
>>> 8.6 - 8.0
0.59999999999999964
Do read the tutorial appendix Mark invited you to read. If you don't, you're going to remain hopelessly confused ;-)
----------
nosy: +tim_one
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue7704>
_______________________________________
More information about the Python-bugs-list
mailing list