Bug in floating point multiplication

Chris Angelico rosuav at gmail.com
Thu Jul 2 17:34:55 CEST 2015

On Fri, Jul 3, 2015 at 1: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.

>From previous discussions I happen to know that Steven normally runs
everything with "from __future__ import division" active (and possibly
others? not sure), so just assume he means to work with floats here.
Steven, I think this is one of the downsides of using future
directives by default - you forget that your code can't always be
copied and pasted to other people :)


More information about the Python-list mailing list