Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!newsgate.cistron.nl!newsgate.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.009 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'python3': 0.05; 'happen.': 0.09; 'reports.': 0.09; 'subject:skip:m 10': 0.09; 'python': 0.11; '2.7': 0.13; 'from:name:vincent vande vyvre': 0.16; 'received:195.130': 0.16; 'received:195.130.137': 0.16; 'received :telenet-ops.be': 0.16; 'reproduce': 0.16; 'ubuntu.': 0.16; '\xe9crit': 0.16; 'runs': 0.18; '>>>': 0.20; 'do.': 0.22; 'title,': 0.22; 'header:In-Reply-To:1': 0.24; 'url:bugs': 0.24; 'header:User-Agent:1': 0.26; 'linux': 0.26; 'prints': 0.29; 'correct': 0.29; 'received:be': 0.31; "can't": 0.32; 'anyone': 0.32; 'probably': 0.32; 'url:python': 0.33; "d'aprano": 0.33; 'steven': 0.33; '(for': 0.34; 'to:addr:python-list': 0.35; 'reply.': 0.35; 'url:org': 0.36; 'so,': 0.37; 'hi,': 0.37; 'should': 0.37; 'operating': 0.37; 'subject:: ': 0.37; 'version': 0.38; 'to:addr:python.org': 0.39; 'system.': 0.39; 'your': 0.60; 'necessarily': 0.61; 'more': 0.62; 'charset:windows-1252': 0.65; 'header:Reply-To:1': 0.67; 'reply': 0.67; 'reply-to:no real name:2**0': 0.71 Date: Thu, 02 Jul 2015 17:15:04 +0200 From: Vincent Vande Vyvre Reply-To: vincent.vandevyvre@oqapy.eu User-Agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Bug in floating point multiplication References: <55955048$0$1662$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: <55955048$0$1662$c3e8da3$5496439d@news.astraweb.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit 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: 59 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1435850814 news.xs4all.nl 2945 [2001:888:2000:d::a6]:49413 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:93432 Le 02/07/2015 16:52, Steven D'Aprano a écrit : > 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 > > > Using Jython and IronPython, the loop runs to completion. That is the > correct behaviour, or so I am lead to believe. Using Python 2.6, 2.7 and > 3.3 on Centos and Debian, it prints 2049 and breaks. That should not > happen. If you can reproduce that (for any value of i, not necessarily > 2049), please reply. > > See also http://bugs.python.org/issue24546 for more details. > > > Hi, vincent@tiemoko:~$ python3 Python 3.2.3 (default, Jun 18 2015, 21:46:42) [GCC 4.6.3] on linux2 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 ... 2049 >>> ------------------------------------------------------------------------------- vincent@djoliba:~$ python3 Python 3.4.0 (default, Jun 19 2015, 14:20:21) [GCC 4.8.2] 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 ... >>> Both on Ubuntu. Vincent