Bug in floating point multiplication

Ian Kelly ian.g.kelly at gmail.com
Thu Jul 2 17:38:03 CEST 2015


On Thu, Jul 2, 2015 at 9:26 AM, Paul Rubin <no.email at nospam.invalid> wrote:
> 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.

Oh, duh. That was the problem on my 2.7.6 test as well. I added from
__future__ import division, and now it runs to completion.


More information about the Python-list mailing list