Bug in floating point multiplication

Robin Becker robin at reportlab.com
Thu Jul 2 17:24:29 CEST 2015


On 02/07/2015 15: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
...

as stated the above fails since it produces x==1L for python 2.7 (Python 2.7.8 
(default, Jun 30 2014, 16:08:48) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.)

If I convert old style

x = 1.0 - 1.0/2**53 then the assertion succeeds and the loop does not print.
-- 
Robin Becker


More information about the Python-list mailing list