Bug in floating point multiplication

Irmen de Jong irmen.NOSPAM at xs4all.nl
Thu Jul 2 19:49:49 CEST 2015

On 2-7-2015 16:52, Steven D'Aprano wrote:
> Despite the title, this is not one of the usual "Why can't Python do
> maths?" "bug" reports.
> Can anyone reproduce this behaviour? If so, please reply with the version of
> Python and your operating system. Printing sys.version will probably do.
> x = 1 - 1/2**53
> assert x == 0.9999999999999999
> for i in range(1, 1000000):
>     if int(i*x) == i:
>         print(i); break

I can't reproduce it with any of the pythons I have here, they all run to completion:

Tested on Mac OSX 10.10.4, with a 64-bit core2duo processor. Below are all 64-bit python
2.6.9 (apple supplied), 2.7.6 (apple supplied), 3.4.3 (homebrew), and pypy-2.6.0
(homebrew). I don't have any 32 bit Python implementations on the mac.

Tested on windows 7, with a 64-bit core2quad processor, but using 32-bit python
implementations from python.org: 2.7.9, 3.3.3, 3.4.2, and pypy-2.5.1.

Irmen de Jong

More information about the Python-list mailing list