Bug in floating point multiplication

Paul Rubin no.email at nospam.invalid
Thu Jul 2 17:26:06 CEST 2015


Steven D'Aprano <steve at pearwood.info> writes:
> x = 1 - 1/2**53
> assert x == 0.9999999999999999

In Python 2.x I don't see how that assert can possibly succeed, since
x is the integer 1.  But I tested it anyway on 2.7.5 under Fedora 19
and it threw an assertion error.

I changed it to say 1 - 1/2.0**53 and then the loop runs to completion.

sys.version is:
2.7.5 (default, Nov  3 2014, 14:33:39) \n[GCC 4.8.3 20140911 (Red Hat 4.8.3-7)]


More information about the Python-list mailing list