Path: csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Paul Rubin Newsgroups: comp.lang.python Subject: Re: Bug in floating point multiplication Date: Thu, 02 Jul 2015 08:26:06 -0700 Organization: A noiseless patient Spider Lines: 12 Message-ID: <87a8vepomp.fsf@nightsong.com> References: <55955048$0$1662$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="38b554b2114f997ed08ebb809b0b9924"; logging-data="22645"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX188QhQ/bccFd6agG62KPh0z" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:bmI5a0ThKd+XqE37mg8b0HYGHEs= sha1:5lO9MYxATRsp0buDUBekZa/w5SY= Xref: csiph.com comp.lang.python:93431 Steven D'Aprano 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. I changed it to say 1 - 1/2.0**53 and then the loop runs to completion. sys.version is: 2.7.5 (default, Nov 3 2014, 14:33:39) \n[GCC 4.8.3 20140911 (Red Hat 4.8.3-7)]