Re: Bug in floating point multiplication

2015-07-06 Thread Jonas Wielicki
-BEGIN PGP SIGNED MESSAGE- Hash: SHA512 On 02.07.2015 19:29, Jason Swails wrote: // maths.h #include math.h #include stdio.h int main() { double x; int i; x = 1-pow(0.5, 53); for (i = 1; i 100; i++) { if ((int)(i*x) == i) { printf(%d\n, i); break; } } return 0; } Does

Re: Bug in floating point multiplication

2015-07-06 Thread Jason Swails
On Mon, Jul 6, 2015 at 11:44 AM, Oscar Benjamin oscar.j.benja...@gmail.com wrote: On Sat, 4 Jul 2015 at 02:12 Jason Swails jason.swa...@gmail.com wrote: On Fri, Jul 3, 2015 at 11:13 AM, Oscar Benjamin oscar.j.benja...@gmail.com wrote: On 2 July 2015 at 18:29, Jason Swails

Re: Bug in floating point multiplication

2015-07-06 Thread Oscar Benjamin
On Sat, 4 Jul 2015 at 02:12 Jason Swails jason.swa...@gmail.com wrote: On Fri, Jul 3, 2015 at 11:13 AM, Oscar Benjamin oscar.j.benja...@gmail.com wrote: On 2 July 2015 at 18:29, Jason Swails jason.swa...@gmail.com wrote: Where is the 32 bit one looks like: $ objdump -d a.out.32 | less

Re: Bug in floating point multiplication

2015-07-05 Thread Peter Otten
Laura Creighton wrote: In a message of Fri, 03 Jul 2015 00:52:55 +1000, Steven D'Aprano writes: 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.

Re: Bug in floating point multiplication

2015-07-04 Thread Laura Creighton
In a message of Fri, 03 Jul 2015 00:52:55 +1000, Steven D'Aprano writes: 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

Re: Bug in floating point multiplication

2015-07-03 Thread Oscar Benjamin
On 2 July 2015 at 18:29, Jason Swails jason.swa...@gmail.com wrote: As others have suggested, this is almost certainly a 32-bit vs. 64-bit issue. Consider the following C program: // maths.h #include math.h #include stdio.h int main() { double x; int i; x = 1-pow(0.5, 53);

Re: Bug in floating point multiplication

2015-07-03 Thread Irmen de Jong
On 3-7-2015 7:07, Ned Deily wrote: In article 559579bb$0$2921$e4fe5...@news.xs4all.nl, Irmen de Jong irmen.nos...@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

Re: Bug in floating point multiplication

2015-07-03 Thread Jason Swails
On Fri, Jul 3, 2015 at 11:13 AM, Oscar Benjamin oscar.j.benja...@gmail.com wrote: On 2 July 2015 at 18:29, Jason Swails jason.swa...@gmail.com wrote: As others have suggested, this is almost certainly a 32-bit vs. 64-bit issue. Consider the following C program: // maths.h #include

Re: Bug in floating point multiplication

2015-07-02 Thread Todd
The loop runs to completion for me on openSUSE Tumbleweed and both Python 2.7 64bits and Python 3.4 64bits. On Thu, Jul 2, 2015 at 4:52 PM, Steven D'Aprano st...@pearwood.info wrote: Despite the title, this is not one of the usual Why can't Python do maths? bug reports. Can anyone reproduce

Re: Bug in floating point multiplication

2015-07-02 Thread Robin Becker
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 -

Re: Bug in floating point multiplication

2015-07-02 Thread Paul Rubin
Steven D'Aprano st...@pearwood.info writes: x = 1 - 1/2**53 assert x == 0. 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 -

Bug in floating point multiplication

2015-07-02 Thread Steven D'Aprano
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. for i in

Re: Bug in floating point multiplication

2015-07-02 Thread Chris Angelico
On Fri, Jul 3, 2015 at 1:26 AM, Paul Rubin no.email@nospam.invalid wrote: Steven D'Aprano st...@pearwood.info writes: x = 1 - 1/2**53 assert x == 0. 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

Re: Bug in floating point multiplication

2015-07-02 Thread Ian Kelly
On Thu, Jul 2, 2015 at 9:26 AM, Paul Rubin no.email@nospam.invalid wrote: Steven D'Aprano st...@pearwood.info writes: x = 1 - 1/2**53 assert x == 0. 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

Re: Bug in floating point multiplication

2015-07-02 Thread Todd
On Thu, Jul 2, 2015 at 5:29 PM, Robin Becker ro...@reportlab.com wrote: $ uname -a Linux everest 4.0.6-1-ARCH #1 SMP PREEMPT Tue Jun 23 14:40:31 CEST 2015 i686 GNU/Linux I am wondering if this is a 32bit vs. 64bit thing. Has anyone gotten this problem to work on a 64bit python? --

Re: Bug in floating point multiplication

2015-07-02 Thread Robin Becker
$ 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 ==

Re: Bug in floating point multiplication

2015-07-02 Thread Ian Kelly
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

Re: Bug in floating point multiplication

2015-07-02 Thread Steven D'Aprano
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

Re: Bug in floating point multiplication

2015-07-02 Thread Michael Poeltl
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 st...@pearwood.info [2015-07-02 16:56]: Despite the title, this is not one of the usual Why can't Python do maths? bug

Re: Bug in floating point multiplication

2015-07-02 Thread Chris Angelico
On Fri, Jul 3, 2015 at 12:52 AM, Steven D'Aprano st...@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. for i in range(1,

Re: Bug in floating point multiplication

2015-07-02 Thread Steven D'Aprano
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 -- https://mail.python.org/mailman/listinfo/python-list

Re: Bug in floating point multiplication

2015-07-02 Thread Vincent Vande Vyvre
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 -

Re: Bug in floating point multiplication

2015-07-02 Thread Ian Kelly
On Thu, Jul 2, 2015 at 9:28 AM, Ian Kelly ian.g.ke...@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

Re: Bug in floating point multiplication

2015-07-02 Thread Ned Deily
In article 559579bb$0$2921$e4fe5...@news.xs4all.nl, Irmen de Jong irmen.nos...@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

Re: Bug in floating point multiplication

2015-07-02 Thread duncan smith
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 -

Re: Bug in floating point multiplication

2015-07-02 Thread Jason Swails
On Thu, Jul 2, 2015 at 10:52 AM, Steven D'Aprano st...@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

Re: Bug in floating point multiplication

2015-07-02 Thread Irmen de Jong
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 -

Re: Bug in floating point multiplication

2015-07-02 Thread MRAB
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 -

Re: Bug in floating point multiplication

2015-07-02 Thread Tim Chase
On 2015-07-03 00:52, Steven D'Aprano wrote: x = 1 - 1/2**53 assert x == 0. for i in range(1, 100): 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

Re: Bug in floating point multiplication

2015-07-02 Thread Laurent Pointal
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