Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #93425 > unrolled thread
| Started by | Steven D'Aprano <steve@pearwood.info> |
|---|---|
| First post | 2015-07-03 00:52 +1000 |
| Last post | 2015-07-05 09:38 +0200 |
| Articles | 20 on this page of 23 — 16 participants |
Back to article view | Back to comp.lang.python
Bug in floating point multiplication Steven D'Aprano <steve@pearwood.info> - 2015-07-03 00:52 +1000
Re: Bug in floating point multiplication Michael Poeltl <michael.poeltl@univie.ac.at> - 2015-07-02 17:10 +0200
Re: Bug in floating point multiplication Chris Angelico <rosuav@gmail.com> - 2015-07-03 01:21 +1000
Re: Bug in floating point multiplication Robin Becker <robin@reportlab.com> - 2015-07-02 16:24 +0100
Re: Bug in floating point multiplication Paul Rubin <no.email@nospam.invalid> - 2015-07-02 08:26 -0700
Re: Bug in floating point multiplication Chris Angelico <rosuav@gmail.com> - 2015-07-03 01:34 +1000
Re: Bug in floating point multiplication Steven D'Aprano <steve@pearwood.info> - 2015-07-03 01:41 +1000
Re: Bug in floating point multiplication Ian Kelly <ian.g.kelly@gmail.com> - 2015-07-02 09:38 -0600
Re: Bug in floating point multiplication Vincent Vande Vyvre <vincent.vande.vyvre@telenet.be> - 2015-07-02 17:15 +0200
Re: Bug in floating point multiplication Ian Kelly <ian.g.kelly@gmail.com> - 2015-07-02 09:28 -0600
Re: Bug in floating point multiplication Robin Becker <robin@reportlab.com> - 2015-07-02 16:29 +0100
Re: Bug in floating point multiplication Ian Kelly <ian.g.kelly@gmail.com> - 2015-07-02 09:32 -0600
Re: Bug in floating point multiplication Steven D'Aprano <steve@pearwood.info> - 2015-07-03 01:42 +1000
Re: Bug in floating point multiplication duncan smith <buzzard@invalid.invalid> - 2015-07-02 17:08 +0100
Re: Bug in floating point multiplication MRAB <python@mrabarnett.plus.com> - 2015-07-02 17:20 +0100
Re: Bug in floating point multiplication Tim Chase <python.list@tim.thechases.com> - 2015-07-02 11:59 -0500
Re: Bug in floating point multiplication Irmen de Jong <irmen.NOSPAM@xs4all.nl> - 2015-07-02 19:49 +0200
Re: Bug in floating point multiplication Ned Deily <nad@acm.org> - 2015-07-02 22:07 -0700
Re: Bug in floating point multiplication Irmen de Jong <irmen.NOSPAM@xs4all.nl> - 2015-07-03 18:27 +0200
Re: Bug in floating point multiplication Laurent Pointal <laurent.pointal@free.fr> - 2015-07-02 23:12 +0200
Re: Bug in floating point multiplication Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2015-07-03 16:13 +0100
Re: Bug in floating point multiplication Laura Creighton <lac@openend.se> - 2015-07-05 00:54 +0200
Re: Bug in floating point multiplication Peter Otten <__peter__@web.de> - 2015-07-05 09:38 +0200
Page 1 of 2 [1] 2 Next page →
| From | Steven D'Aprano <steve@pearwood.info> |
|---|---|
| Date | 2015-07-03 00:52 +1000 |
| Subject | Bug in floating point multiplication |
| Message-ID | <55955048$0$1662$c3e8da3$5496439d@news.astraweb.com> |
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.
--
Steven
[toc] | [next] | [standalone]
| From | Michael Poeltl <michael.poeltl@univie.ac.at> |
|---|---|
| Date | 2015-07-02 17:10 +0200 |
| Message-ID | <mailman.246.1435850461.3674.python-list@python.org> |
| In reply to | #93425 |
hi Steven, I'm running python-3.4.2 on a linuxmint16 box and CANNOT reproduce it is just that int(i*x) == i is never True! hope that helps regards Michael * Steven D'Aprano <steve@pearwood.info> [2015-07-02 16:56]: > 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. > > > > -- > Steven > > -- > https://mail.python.org/mailman/listinfo/python-list -- Michael Poeltl <michael.poeltl@univie.ac.at> Computational Materials Physics at University Wien, Sensengasse 8/12, A-1090 Wien, AUSTRIA http://cmp.univie.ac.at/ http://homepage.univie.ac.at/michael.poeltl/ using elinks-0.12, mutt-1.5.21, and vim-7.3, with python-3.4.2, on linux mint 16 (petra) :-) fon: +43-1-4277-51409 "Lehrend lernen wir!"
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2015-07-03 01:21 +1000 |
| Message-ID | <mailman.247.1435850477.3674.python-list@python.org> |
| In reply to | #93425 |
On Fri, Jul 3, 2015 at 12:52 AM, Steven D'Aprano <steve@pearwood.info> wrote: > 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 > I suspect for Py2 you need to say 1/2.0, or insist on a future directive. Otherwise the assertion fails, x is simply 1, and the loop instantly halts, none of which is buggy behaviour. Testing on a 64-bit Debian Jessie, these all run to completion: Python 3.6.0a0 (default:5c901b39c6b7, Jun 28 2015, 09:13:39) Python 3.5.0b1+ (default:7255af1a1c50+, May 26 2015, 00:39:06) Python 3.4.2 (default, Oct 8 2014, 10:45:20) Python 2.7.9 (default, Mar 1 2015, 12:57:24) Testing on a 32-bit Debian Jessie, these all print 2049 and stop: Python 3.4.2 (default, Oct 8 2014, 13:14:40) Python 3.3.3 (default, Dec 31 2013, 19:11:08) Python 2.7.9 (default, Mar 1 2015, 18:22:53) Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40) (2.6.6 isn't actually supported on Jessie, it just happens to be laying around.) On 32-bit AntiX, these both print 2049 and stop: Python 3.4.3+ (default, Jun 2 2015, 14:09:35) Python 2.7.10 (default, Jun 1 2015, 16:21:46) Looks like it's an issue with 32-bit builds only. And not on Windows - I spun up a Win 7 VM and tested it to completion: Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) [MSC v.1600 32 bit (Intel)] on win32 Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)] on win32 Over-eager optimization somewhere? ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Robin Becker <robin@reportlab.com> |
|---|---|
| Date | 2015-07-02 16:24 +0100 |
| Message-ID | <mailman.248.1435850672.3674.python-list@python.org> |
| In reply to | #93425 |
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
[toc] | [prev] | [next] | [standalone]
| From | Paul Rubin <no.email@nospam.invalid> |
|---|---|
| Date | 2015-07-02 08:26 -0700 |
| Message-ID | <87a8vepomp.fsf@nightsong.com> |
| In reply to | #93425 |
Steven D'Aprano <steve@pearwood.info> 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)]
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2015-07-03 01:34 +1000 |
| Message-ID | <mailman.253.1435851297.3674.python-list@python.org> |
| In reply to | #93431 |
On Fri, Jul 3, 2015 at 1:26 AM, Paul Rubin <no.email@nospam.invalid> wrote: > Steven D'Aprano <steve@pearwood.info> 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. >From previous discussions I happen to know that Steven normally runs everything with "from __future__ import division" active (and possibly others? not sure), so just assume he means to work with floats here. Steven, I think this is one of the downsides of using future directives by default - you forget that your code can't always be copied and pasted to other people :) ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve@pearwood.info> |
|---|---|
| Date | 2015-07-03 01:41 +1000 |
| Message-ID | <55955bbe$0$1646$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #93436 |
On Fri, 3 Jul 2015 01:34 am, Chris Angelico wrote: > From previous discussions I happen to know that Steven normally runs > everything with "from __future__ import division" active (and possibly > others? not sure), so just assume he means to work with floats here. > Steven, I think this is one of the downsides of using future > directives by default - you forget that your code can't always be > copied and pasted to other people :) /me hangs his head in shame Yes, you've diagnosed the problem correctly. Sorry for the confusion. -- Steven
[toc] | [prev] | [next] | [standalone]
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2015-07-02 09:38 -0600 |
| Message-ID | <mailman.255.1435851526.3674.python-list@python.org> |
| In reply to | #93431 |
On Thu, Jul 2, 2015 at 9:26 AM, Paul Rubin <no.email@nospam.invalid> wrote: > Steven D'Aprano <steve@pearwood.info> 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. Oh, duh. That was the problem on my 2.7.6 test as well. I added from __future__ import division, and now it runs to completion.
[toc] | [prev] | [next] | [standalone]
| From | Vincent Vande Vyvre <vincent.vande.vyvre@telenet.be> |
|---|---|
| Date | 2015-07-02 17:15 +0200 |
| Message-ID | <mailman.249.1435850814.3674.python-list@python.org> |
| In reply to | #93425 |
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
[toc] | [prev] | [next] | [standalone]
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2015-07-02 09:28 -0600 |
| Message-ID | <mailman.250.1435850964.3674.python-list@python.org> |
| In reply to | #93425 |
On my Chromebook, using Python 2.7.6 from the Ubuntu Trusty distribution, I get AssertionError, and x == 1. In Python 3.4.0 on the same system, the code runs to completion. Both Pythons appear to be 64-bit builds. On my Mint 17.1 desktop (which should be using the same packages), I get the same results. On Thu, Jul 2, 2015 at 8:52 AM, Steven D'Aprano <steve@pearwood.info> 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 > 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. > > > > -- > Steven > > -- > https://mail.python.org/mailman/listinfo/python-list
[toc] | [prev] | [next] | [standalone]
| From | Robin Becker <robin@reportlab.com> |
|---|---|
| Date | 2015-07-02 16:29 +0100 |
| Message-ID | <mailman.251.1435850983.3674.python-list@python.org> |
| In reply to | #93425 |
$ uname -a
Linux everest 4.0.6-1-ARCH #1 SMP PREEMPT Tue Jun 23 14:40:31 CEST 2015 i686
GNU/Linux
robin@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@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@everest:~/devel/filps
--
Robin Becker
[toc] | [prev] | [next] | [standalone]
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2015-07-02 09:32 -0600 |
| Message-ID | <mailman.252.1435851204.3674.python-list@python.org> |
| In reply to | #93425 |
On Thu, Jul 2, 2015 at 9:28 AM, Ian Kelly <ian.g.kelly@gmail.com> wrote: > On my Chromebook, using Python 2.7.6 from the Ubuntu Trusty > distribution, I get AssertionError, and x == 1. > > In Python 3.4.0 on the same system, the code runs to completion. Both > Pythons appear to be 64-bit builds. > > On my Mint 17.1 desktop (which should be using the same packages), I > get the same results. Apologies for the accidental top-posting. Also, the full sys.version string for the 2.7.6 Python is: 2.7.6 (default, Jun 22 2015, 17:58:13) [GCC 4.8.2]
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve@pearwood.info> |
|---|---|
| Date | 2015-07-03 01:42 +1000 |
| Message-ID | <55955bd7$0$1646$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #93425 |
On Fri, 3 Jul 2015 12:52 am, Steven D'Aprano wrote: > x = 1 - 1/2**53 Ooops, sorry I forgot that I had already run "from __future__ import division". Otherwise that line needs to be: x = 1 - 1.0/2**53 -- Steven
[toc] | [prev] | [next] | [standalone]
| From | duncan smith <buzzard@invalid.invalid> |
|---|---|
| Date | 2015-07-02 17:08 +0100 |
| Message-ID | <559561fd$0$16022$862e30e2@ngroups.net> |
| In reply to | #93425 |
On 02/07/15 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 > 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. > > > Python 2.7.6 (default, Jun 22 2015, 17:58:13) [GCC 4.8.2] on linux2 Type "copyright", "credits" or "license()" for more information. >>> from __future__ import division >>> x = 1 - 1/2**53 >>> assert x == 0.9999999999999999 >>> for i in range(1, 1000000): if int(i*x) == i: print(i); break >>> Python 3.4.0 (default, Jun 19 2015, 14:20:21) [GCC 4.8.2] on linux Type "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 >>> Ubuntu 14.04 Duncan
[toc] | [prev] | [next] | [standalone]
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2015-07-02 17:20 +0100 |
| Message-ID | <mailman.257.1435854219.3674.python-list@python.org> |
| In reply to | #93425 |
On 2015-07-02 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 > 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. > These are all on Windows 8.1 with CPython from www.python.org. With "x = 1 - 1.0/2**53" (needed for Python 2.x) they all passed. 2.5.4 (r254:67916, Dec 23 2008, 15:19:34) [MSC v.1400 64 bit (AMD64)] 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] 2.6.6 (r266:84297, Aug 24 2010, 18:13:38) [MSC v.1500 64 bit (AMD64)] 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] 2.7.7 (default, Jun 1 2014, 14:21:57) [MSC v.1500 64 bit (AMD64)] 2.7.7 (default, Jun 1 2014, 14:17:13) [MSC v.1500 32 bit (Intel)] 3.1.4 (default, Jun 12 2011, 14:16:16) [MSC v.1500 64 bit (AMD64)] 3.1.4 (default, Jun 12 2011, 15:05:44) [MSC v.1500 32 bit (Intel)] 3.2.5 (default, May 15 2013, 23:07:10) [MSC v.1500 64 bit (AMD64)] 3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)] 3.3.5 (v3.3.5:62cf4e77f785, Mar 9 2014, 10:35:05) [MSC v.1600 64 bit (AMD64)] 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:03:43) [MSC v.1600 32 bit (Intel)] 3.4.2 (v3.4.2:ab2c023a9432, Oct 6 2014, 22:16:31) [MSC v.1600 64 bit (AMD64)] 3.4.2 (v3.4.2:ab2c023a9432, Oct 6 2014, 22:15:05) [MSC v.1600 32 bit (Intel)] 3.5.0b2 (v3.5.0b2:7a088af5615b, May 31 2015, 06:22:19) [MSC v.1900 64 bit (AMD64)] 3.5.0b2 (v3.5.0b2:7a088af5615b, May 31 2015, 06:08:44) [MSC v.1900 32 bit (Intel)]
[toc] | [prev] | [next] | [standalone]
| From | Tim Chase <python.list@tim.thechases.com> |
|---|---|
| Date | 2015-07-02 11:59 -0500 |
| Message-ID | <mailman.260.1435857340.3674.python-list@python.org> |
| In reply to | #93425 |
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 "<stdin>", line 1, in <module> 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
[toc] | [prev] | [next] | [standalone]
| From | Irmen de Jong <irmen.NOSPAM@xs4all.nl> |
|---|---|
| Date | 2015-07-02 19:49 +0200 |
| Message-ID | <559579bb$0$2921$e4fe514c@news.xs4all.nl> |
| In reply to | #93425 |
On 2-7-2015 16: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 > for i in range(1, 1000000): > if int(i*x) == i: > print(i); break I can't reproduce it with any of the pythons I have here, they all run to completion: Tested on Mac OSX 10.10.4, with a 64-bit core2duo processor. Below are all 64-bit python implementations: 2.6.9 (apple supplied), 2.7.6 (apple supplied), 3.4.3 (homebrew), and pypy-2.6.0 (homebrew). I don't have any 32 bit Python implementations on the mac. Tested on windows 7, with a 64-bit core2quad processor, but using 32-bit python implementations from python.org: 2.7.9, 3.3.3, 3.4.2, and pypy-2.5.1. Irmen de Jong
[toc] | [prev] | [next] | [standalone]
| From | Ned Deily <nad@acm.org> |
|---|---|
| Date | 2015-07-02 22:07 -0700 |
| Message-ID | <mailman.265.1435900060.3674.python-list@python.org> |
| In reply to | #93448 |
In article <559579bb$0$2921$e4fe514c@news.xs4all.nl>, Irmen de Jong <irmen.NOSPAM@xs4all.nl> wrote: > Tested on Mac OSX 10.10.4, with a 64-bit core2duo processor. Below are all > 64-bit python > implementations: > 2.6.9 (apple supplied), 2.7.6 (apple supplied), 3.4.3 (homebrew), and > pypy-2.6.0 > (homebrew). I don't have any 32 bit Python implementations on the mac. Sure you do! $ /usr/bin/python2.7 -c 'import sys;print(sys.maxsize)' 9223372036854775807 $ arch -i386 /usr/bin/python2.7 -c 'import sys;print(sys.maxsize)' 2147483647 -- Ned Deily, nad@acm.org
[toc] | [prev] | [next] | [standalone]
| From | Irmen de Jong <irmen.NOSPAM@xs4all.nl> |
|---|---|
| Date | 2015-07-03 18:27 +0200 |
| Message-ID | <5596b7ed$0$2851$e4fe514c@news.xs4all.nl> |
| In reply to | #93460 |
On 3-7-2015 7:07, Ned Deily wrote: > In article <559579bb$0$2921$e4fe514c@news.xs4all.nl>, > Irmen de Jong <irmen.NOSPAM@xs4all.nl> wrote: >> Tested on Mac OSX 10.10.4, with a 64-bit core2duo processor. Below are all >> 64-bit python >> implementations: >> 2.6.9 (apple supplied), 2.7.6 (apple supplied), 3.4.3 (homebrew), and >> pypy-2.6.0 >> (homebrew). I don't have any 32 bit Python implementations on the mac. > > Sure you do! > > $ /usr/bin/python2.7 -c 'import sys;print(sys.maxsize)' > 9223372036854775807 > $ arch -i386 /usr/bin/python2.7 -c 'import sys;print(sys.maxsize)' > 2147483647 > Woops! Totally forgot about the multiarch thing. Thanks for reminding me. It doesn't change the outcome of the test though, when running the little test code with the 32-bit versions they both (2.6 and 2.7) ran to completion. Irmen
[toc] | [prev] | [next] | [standalone]
| From | Laurent Pointal <laurent.pointal@free.fr> |
|---|---|
| Date | 2015-07-02 23:12 +0200 |
| Message-ID | <5595a940$0$3070$426a74cc@news.free.fr> |
| In reply to | #93425 |
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. <zip> On Kubuntu 15.04, it works. Python 3.4.3 (default, Mar 26 2015, 22:03:40) [GCC 4.9.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 ... >>> A+ Laurent.
[toc] | [prev] | [next] | [standalone]
Page 1 of 2 [1] 2 Next page →
Back to top | Article view | comp.lang.python
csiph-web