Bug in floating point multiplication

Robin Becker robin at reportlab.com
Thu Jul 2 11:29:40 EDT 2015



$ uname -a
Linux everest 4.0.6-1-ARCH #1 SMP PREEMPT Tue Jun 23 14:40:31 CEST 2015 i686 
GNU/Linux
robin at everest:~
$ python2
Python 2.7.10 (default, May 26 2015, 04:28:58)
[GCC 5.1.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> x = 1.0 - 1.0/2**53
 >>> assert x == 0.9999999999999999
 >>> for i in range(1, 1000000):
...     if int(i*x) == i:
...         print(i); break
...
2049
 >>>
robin at everest:~
$ python
Python 3.4.3 (default, Mar 26 2015, 07:36:01)
[GCC 4.9.2 20150304 (prerelease)] on linux
Type "help", "copyright", "credits" or "license" for more information.
 >>>
KeyboardInterrupt
 >>> x = 1 - 1/2**53
 >>> assert x == 0.9999999999999999
 >>>  for i in range(1, 1000000):
   File "<stdin>", line 1
     for i in range(1, 1000000):
     ^
IndentationError: unexpected indent
 >>> for i in range(1, 1000000):
...     if int(i*x) == i:
...          print(i); break
...
2049
 >>>
robin at everest:~/devel/filps




-- 
Robin Becker



More information about the Python-list mailing list