Re: Python fails on math

2011-03-09 Thread Ben
On Feb 25, 12:33 am, Steven D'Aprano steve +comp.lang.pyt...@pearwood.info wrote: On Thu, 24 Feb 2011 10:40:45 -0600, Robert Kern wrote: On 2/24/11 5:55 AM, Steven D'Aprano wrote: On Wed, 23 Feb 2011 13:26:05 -0800, John Nagle wrote: The IEEE 754 compliant FPU on most machines today,

Re: Python fails on math

2011-03-09 Thread Mark Dickinson
On Feb 25, 12:52 am, Grant Edwards inva...@invalid.invalid wrote: So I think the C standard actually forces the compiler to convert results to 64-bits at the points where a store to a temporary variable happens. I'm not sure that this is true. IIRC, C99 + Annex F forces this, but C99 by

Re: Re: Python fails on math

2011-02-25 Thread Heather Brown
On 01/-10/-28163 02:59 PM, Grant Edwards wrote: On 2011-02-25, Steven D'Apranosteve+comp.lang.pyt...@pearwood.info wrote: C double *variables* are, but as John suggests, C compilers are allowed (to my knowledge) to keep intermediate results of an expression in the larger-precision FPU

Re: Python fails on math

2011-02-24 Thread Steven D'Aprano
On Wed, 23 Feb 2011 13:26:05 -0800, John Nagle wrote: The IEEE 754 compliant FPU on most machines today, though, has an 80-bit internal representation. If you do a sequence of operations that retain all the intermediate results in the FPU registers, you get 16 more bits of precision than if

Re: Python fails on math

2011-02-24 Thread Ethan Furman
Steven D'Aprano wrote: On Wed, 23 Feb 2011 13:26:05 -0800, John Nagle wrote: The IEEE 754 compliant FPU on most machines today, though, has an 80-bit internal representation. If you do a sequence of operations that retain all the intermediate results in the FPU registers, you get 16 more bits

Re: Python fails on math

2011-02-24 Thread D'Arcy J.M. Cain
On Thu, 24 Feb 2011 04:56:46 -0800 Ethan Furman et...@stoneleaf.us wrote: The IEEE 754 compliant FPU on most machines today, though, has an 80-bit internal representation. If you do a sequence of operations that retain all the intermediate results in the FPU registers, you get 16 more bits

Re: Python fails on math

2011-02-24 Thread Mel
D'Arcy J.M. Cain wrote: On Thu, 24 Feb 2011 04:56:46 -0800 Ethan Furman et...@stoneleaf.us wrote: That's a big if though. Which languages support such a thing? C doubles are 64 bit, same as Python. Assembly! :) Really? Why would you need that level of precision just to gather all

Re: Python fails on math

2011-02-24 Thread Robert Kern
On 2/24/11 5:55 AM, Steven D'Aprano wrote: On Wed, 23 Feb 2011 13:26:05 -0800, John Nagle wrote: The IEEE 754 compliant FPU on most machines today, though, has an 80-bit internal representation. If you do a sequence of operations that retain all the intermediate results in the FPU registers,

Re: Python fails on math

2011-02-24 Thread Steven D'Aprano
On Thu, 24 Feb 2011 10:40:45 -0600, Robert Kern wrote: On 2/24/11 5:55 AM, Steven D'Aprano wrote: On Wed, 23 Feb 2011 13:26:05 -0800, John Nagle wrote: The IEEE 754 compliant FPU on most machines today, though, has an 80-bit internal representation. If you do a sequence of operations that

Re: Python fails on math

2011-02-24 Thread Westley Martínez
On Fri, 2011-02-25 at 00:33 +, Steven D'Aprano wrote: On Thu, 24 Feb 2011 10:40:45 -0600, Robert Kern wrote: On 2/24/11 5:55 AM, Steven D'Aprano wrote: On Wed, 23 Feb 2011 13:26:05 -0800, John Nagle wrote: The IEEE 754 compliant FPU on most machines today, though, has an 80-bit

Re: Python fails on math

2011-02-24 Thread Grant Edwards
On 2011-02-25, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: C double *variables* are, but as John suggests, C compilers are allowed (to my knowledge) to keep intermediate results of an expression in the larger-precision FPU registers. The final result does get shoved back into

Re: Python fails on math

2011-02-24 Thread Grant Edwards
On 2011-02-25, Westley Mart?nez aniko...@gmail.com wrote: Maybe I'm wrong, but wouldn't compiling Python with a compiler that supports extended precision for intermediates allow Python to use extended precision for its immediates? I'm not sure what you mean by immediates, but I don't think

Re: Python fails on math

2011-02-24 Thread Westley Martínez
On Fri, 2011-02-25 at 00:57 +, Grant Edwards wrote: On 2011-02-25, Westley Mart?nez aniko...@gmail.com wrote: Maybe I'm wrong, but wouldn't compiling Python with a compiler that supports extended precision for intermediates allow Python to use extended precision for its immediates?

Re: Python fails on math

2011-02-23 Thread Grant Edwards
On 2011-02-23, Terry Reedy tjre...@udel.edu wrote: On 2/22/2011 2:42 PM, Grant Edwards wrote: Except that Python (and computer languages in general) don't deal with real numbers. They deal with floating point numbers, which aren't the same thing. [In case anybody is still fuzzy about that.]

Re: Python fails on math

2011-02-23 Thread John Nagle
On 2/22/2011 9:59 AM, Roy Smith wrote: In articleik0rmr$ck4$1...@reader1.panix.com, Grant Edwardsinvalid@invalid.invalid wrote: Python doesn't do equations. Python does floating point operations. More generally, all general-purpose programming languages have the same problem. You'll see

Python fails on math

2011-02-22 Thread christian schulze
Hey guys, I just found out, how much Python fails on simple math. I checked a simple equation for a friend. [code] from math import e as e from math import sqrt as sqrt 2*e*sqrt(3) - 2*e == 2*e*(sqrt(3) - 1) False [/code] So WTF? The equation is definitive equivalent. (See http://mathbin.net

Re: Python fails on math

2011-02-22 Thread Nitin Pawar
out, how much Python fails on simple math. I checked a simple equation for a friend. [code] from math import e as e from math import sqrt as sqrt 2*e*sqrt(3) - 2*e == 2*e*(sqrt(3) - 1) False [/code] So WTF? The equation is definitive equivalent. (See http://mathbin.net/59158) PS: #1

Re: Python fails on math

2011-02-22 Thread Grigory Javadyan
-- Forwarded message -- From: Grigory Javadyan grigory.javad...@gmail.com Date: Tue, Feb 22, 2011 at 5:32 PM Subject: Re: Python fails on math To: christian schulze xcr...@googlemail.com Everybody knows you can't just compare floating point values for equality with a simple

Re: Python fails on math

2011-02-22 Thread Mel
christian schulze wrote: #1: 2.0 * e * sqrt(3.0) - 2.0 * e 3.9798408154464964 #2: 2.0 * e * (sqrt(3.0) -1.0) 3.979840815446496 I was wondering what exactly is failing here. The math module? Python, or the IEEE specifications? Limited-precision calculation, computer floating-point for

Re: Python fails on math

2011-02-22 Thread Tim Wintle
On Tue, 2011-02-22 at 05:20 -0800, christian schulze wrote: [code] from math import e as e from math import sqrt as sqrt 2*e*sqrt(3) - 2*e == 2*e*(sqrt(3) - 1) False [/code] I was wondering what exactly is failing here. The math module? Python, or the IEEE specifications? I'm not sure

Re: Python fails on math

2011-02-22 Thread Benjamin Kaplan
On Tue, Feb 22, 2011 at 8:20 AM, christian schulze xcr...@googlemail.com wrote: Hey guys, I just found out, how much Python fails on simple math. I checked a simple equation for a friend. [code] from math import e as e from math import sqrt as sqrt 2*e*sqrt(3) - 2*e == 2*e*(sqrt(3) - 1

Re: Python fails on math

2011-02-22 Thread Ian
On 22/02/2011 13:20, christian schulze wrote: Hey guys, I just found out, how much Python fails on simple math. I checked a simple equation for a friend. [code] from math import e as e from math import sqrt as sqrt 2*e*sqrt(3) - 2*e == 2*e*(sqrt(3) - 1) False [/code] So WTF? The equation

Re: Python fails on math

2011-02-22 Thread Jean-Michel Pichavant
christian schulze wrote: Hey guys, I just found out, how much Python fails on simple math. I checked a simple equation for a friend. [code] from math import e as e from math import sqrt as sqrt 2*e*sqrt(3) - 2*e == 2*e*(sqrt(3) - 1) e has no accurate representation in computer science

Re: Python fails on math

2011-02-22 Thread Duncan Booth
christian schulze xcr...@googlemail.com wrote: Hey guys, I just found out, how much Python fails on simple math. I checked a simple equation for a friend. [code] from math import e as e from math import sqrt as sqrt 2*e*sqrt(3) - 2*e == 2*e*(sqrt(3) - 1) False [/code] Try the same

Re: Python fails on math

2011-02-22 Thread David C. Ullrich
In article 127fc97e-c210-4df1-952c-f6383d44b...@o8g2000vbq.googlegroups.com, christian schulze xcr...@googlemail.com wrote: Hey guys, I just found out, how much Python fails on simple math. I checked a simple equation for a friend. [code] from math import e as e from math import

Re: Python fails on math

2011-02-22 Thread Grant Edwards
On 2011-02-22, christian schulze xcr...@googlemail.com wrote: Hey guys, I just found out, how much Python fails on simple math. Python doesn't do math. It does floating point operations. They're different. Seriously. On all of the platforms I know of, it's IEEE 754 (base-2) floating point

Re: Python fails on math

2011-02-22 Thread Roy Smith
In article ik0rmr$ck4$1...@reader1.panix.com, Grant Edwards invalid@invalid.invalid wrote: Python doesn't do equations. Python does floating point operations. More generally, all general-purpose programming languages have the same problem. You'll see the same issues in Fortran, C, Java,

Re: Python fails on math

2011-02-22 Thread Ian Kelly
On Tue, Feb 22, 2011 at 9:54 AM, David C. Ullrich dullr...@sprynet.com wrote: Anyway, I don't know why you're jumping to the conclusion that it's Python that's wrong here. Could be the math you learned in school is wrong. I mean you're assuming that (*)       a(b+c) = ab + ac but what makes

Re: Python fails on math

2011-02-22 Thread Grant Edwards
On 2011-02-22, Roy Smith r...@panix.com wrote: In article ik0rmr$ck4$1...@reader1.panix.com, Grant Edwards invalid@invalid.invalid wrote: Python doesn't do equations. Python does floating point operations. More generally, all general-purpose programming languages have the same problem.

Re: Python fails on math

2011-02-22 Thread Grant Edwards
On 2011-02-22, Ian Kelly ian.g.ke...@gmail.com wrote: On Tue, Feb 22, 2011 at 9:54 AM, David C. Ullrich dullr...@sprynet.com wrote: Anyway, I don't know why you're jumping to the conclusion that it's Python that's wrong here. Could be the math you learned in school is wrong. I mean you're

Re: Python fails on math

2011-02-22 Thread Stephen Hansen
On 2/22/11 5:20 AM, christian schulze wrote: I just found out, how much Python fails on simple math. 2*e*sqrt(3) - 2*e == 2*e*(sqrt(3) - 1) Everyone else has answered very well, so I won't comment on the actual question at hand-- it seems to have been answered completely. But! I shall go all

Re: Python fails on math

2011-02-22 Thread sturlamolden
On 22 Feb, 14:20, christian schulze xcr...@googlemail.com wrote: Hey guys, I just found out, how much Python fails on simple math. I checked a simple equation for a friend. Python does not fail. Floating point arithmetics and numerical approximations will do this. If you need symbolic maths

Re: Python fails on math

2011-02-22 Thread christian schulze
On 22 Feb., 21:18, Stephen Hansen me+list/pyt...@ixokai.io wrote: On 2/22/11 5:20 AM, christian schulze wrote: I just found out, how much Python fails on simple math. 2*e*sqrt(3) - 2*e == 2*e*(sqrt(3) - 1) Everyone else has answered very well, so I won't comment on the actual question

Re: Python fails on math

2011-02-22 Thread Terry Reedy
On 2/22/2011 2:42 PM, Grant Edwards wrote: Except that Python (and computer languages in general) don't deal with real numbers. They deal with floating point numbers, which aren't the same thing. [In case anybody is still fuzzy about that.] In particular, floats are a fixed finite set of