python 3.44 float addition bug?

Ian Kelly ian.g.kelly at gmail.com
Fri Jun 27 12:18:54 EDT 2014


On Thu, Jun 26, 2014 at 9:24 PM, Chris Angelico <rosuav at gmail.com> wrote:
> But you're right that this can be very surprising. And it's inherent
> to the concept of digits having more range than just "high" or "low",
> so there's no way you can get this with binary floats.

For an average of two numbers, I think that's true.  For an average of
more than two numbers, it's possible.

>>> a = 2.0 ** 53 - 1
>>> b = 2.0 ** 53 - 2
>>> a
9007199254740991.0
>>> b
9007199254740990.0
>>> (a + b + b) / 3
9007199254740989.0



More information about the Python-list mailing list