Path: csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.011 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'python3': 0.05; 'fails.': 0.09; 'subject:skip:m 10': 0.09; 'x86_64': 0.09; 'python': 0.11; 'weird': 0.15; '-tkc': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'uname': 0.16; 'wrote:': 0.16; '>>>': 0.20; '"",': 0.22; 'header :In-Reply-To:1': 0.24; '(most': 0.24; 'linux': 0.26; "d'aprano": 0.33; 'steven': 0.33; 'traceback': 0.33; 'file': 0.34; 'to:addr :python-list': 0.35; 'received:10': 0.37; 'subject:: ': 0.37; 'charset:us-ascii': 0.37; 'skip:3 10': 0.38; 'to:addr:python.org': 0.39; 'more': 0.62; 'mar': 0.65; 'received:162.253': 0.84; 'smp': 0.84; '2014,': 0.91 X-Sender-Id: wwwh|x-authuser|tim@thechases.com X-Sender-Id: wwwh|x-authuser|tim@thechases.com X-MC-Relay: Neutral X-MailChannels-SenderId: wwwh|x-authuser|tim@thechases.com X-MailChannels-Auth-Id: wwwh X-MC-Loop-Signature: 1435856388821:1682273732 X-MC-Ingress-Time: 1435856388821 Date: Thu, 2 Jul 2015 11:59:49 -0500 From: Tim Chase To: python-list@python.org Subject: Re: Bug in floating point multiplication In-Reply-To: <55955048$0$1662$c3e8da3$5496439d@news.astraweb.com> References: <55955048$0$1662$c3e8da3$5496439d@news.astraweb.com> X-Mailer: Claws Mail 3.11.1 (GTK+ 2.24.25; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-AuthUser: tim@thechases.com X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 43 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1435857340 news.xs4all.nl 2878 [2001:888:2000:d::a6]:52023 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:93446 On 2015-07-03 00:52, Steven D'Aprano wrote: > x = 1 - 1/2**53 > assert x == 0.9999999999999999 > for i in range(1, 1000000): > if int(i*x) == i: > print(i); break tkc@debian:~$ python Python 2.7.9 (default, Mar 1 2015, 12:57:24) [GCC 4.9.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> x = 1 - 1/2**53 >>> assert x == 0.9999999999999999 Traceback (most recent call last): File "", line 1, in AssertionError >>> for i in range(1, 1000000): ... if int(i*x) == i: ... print(i); break ... 1 >>> x 1 >>> ^D tkc@debian:~$ python3 Python 3.4.2 (default, Oct 8 2014, 10:45:20) [GCC 4.9.1] on linux Type "help", "copyright", "credits" or "license" for more information. >>> x = 1 - 1/2**53 >>> assert x == 0.9999999999999999 >>> for i in range(1, 1000000): ... if int(i*x) == i: ... print(i); break ... >>> ^D tkc@debian:~$ uname -a Linux bigbox 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt9-3~deb8u1 (2015-04-24) x86_64 GNU/Linux Weird that on 2.7, the assert fails. -tkc