[issue7704] Math calculation problem (1.6-1.0)>0.6, python said TRUE

Mark Dickinson report at bugs.python.org
Thu Jan 14 21:54:27 CET 2010


Mark Dickinson <dickinsm at gmail.com> added the comment:

This is not a bug:  Python, like many other computer languages, stores floats in binary.  The values 1.6 and 0.6 aren't exactly representable in the internal format used, so the stored versions of 1.6 and 0.6 are actually just very close approximations to those values.  It just so happens that the approximation for 1.6 is a tiny amount larger than 1.6 (the exact value stored is 1.600000000000000088817841970012523233890533447265625), while the approximation for 0.6 is a tiny amount smaller than 0.6 (the exact value is 0.59999999999999997779553950749686919152736663818359375).

I recommend looking at the appendix to the Python tutorial for more information about floating point:

http://docs.python.org/tutorial/floatingpoint.html

----------
nosy: +mark.dickinson
resolution:  -> invalid
status: open -> closed

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue7704>
_______________________________________


More information about the Python-bugs-list mailing list