Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #93446
| Date | 2015-07-02 11:59 -0500 |
|---|---|
| From | Tim Chase <python.list@tim.thechases.com> |
| Subject | Re: Bug in floating point multiplication |
| References | <55955048$0$1662$c3e8da3$5496439d@news.astraweb.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.260.1435857340.3674.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
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
csiph-web