Re: Floating point multiplication in python

2011-09-07 Thread Christophe Chong
And then we learned in class what happens when you're calculating "0.1" with different precision in the industry. http://www.ima.umn.edu/~arnold/disasters/patriot.html Beware. On Tue, Sep 6, 2011 at 3:14 AM, Thomas Rachel < nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa...@spamschutz.glglgl.de> wrot

Re: Floating point multiplication in python

2011-09-07 Thread Terry Reedy
On 9/7/2011 12:51 AM, Steven D'Aprano wrote: So given a float x, when you square it you get this: Exact values: a*a = a**2 Float values: x*x = (a+e)(a+e) = a**2 + 2*a*e + e**2 So the error term has increased from e to (2*a*e+e**2). It is usual to assume that e**2 is small e

Re: Floating point multiplication in python

2011-09-07 Thread Gelonida N
On 09/07/2011 06:51 AM, Steven D'Aprano wrote: 11258999068426240 > > Error in float 1.1*1.1: > b = F(11, 10)**2 y = F.from_float(1.1**2) f = y - b print f > 21/112589990684262400 > > which is slightly more than double e above, and slightly less than our > estimate of 2*a*e =

Re: Floating point multiplication in python

2011-09-06 Thread Steven D'Aprano
On Wed, 7 Sep 2011 02:07 am Thomas 'PointedEars' Lahn wrote: > Thomas Rachel wrote: > >> Now if you multiply two values with an error, the error also propagates >> into the result - PLUs the result can have its own error source - in the >> same order of magnitude. >> >> (a+e) * (a+e) = a*a + 2*a

Re: Floating point multiplication in python

2011-09-06 Thread Thomas 'PointedEars' Lahn
Thomas Rachel wrote: > Now if you multiply two values with an error, the error also propagates > into the result - PLUs the result can have its own error source - in the > same order of magnitude. > > (a+e) * (a+e) = a*a + 2*a*e + e*e. So your new error term is 2*a*e + e*e > or (2*a + e) * e. Yo

Re: Floating point multiplication in python

2011-09-06 Thread Thomas Rachel
Am 06.09.2011 07:57 schrieb xyz: hi all: As we know , 1.1 * 1.1 is 1.21 . But in python ,I got following : 1.1 * 1.1 1.2102 why python get wrong result? Who can tell me where's the 0.0002 from? 1.1 does not fit in a binary floating point number. It is approximate

Re: Floating point multiplication in python

2011-09-06 Thread Duncan Booth
Gary Herron wrote: > (But try: >print 1.1*1.1 > and see that the print statement does hide the roundoff error from you.) That varies according to the version of Python you are using. On my system: Python 2.7 (r27:82525, Jul 4 2010, 09:01:59) [MSC v.1500 32 bit (Intel)] on win32 Type "help

Re: Floating point multiplication in python

2011-09-06 Thread Steven D'Aprano
On Tue, 6 Sep 2011 03:57 pm xyz wrote: > hi all: > > As we know , 1.1 * 1.1 is 1.21 . > But in python ,I got following : > 1.1 * 1.1 > 1.2102 The problem is that 1.1 is a *decimal* number, but computers use *binary*, and it is impossible to express 1.1 exactly as a binary num

Re: Floating point multiplication in python

2011-09-06 Thread Gary Herron
On 09/05/2011 10:57 PM, xyz wrote: hi all: As we know , 1.1 * 1.1 is 1.21 . But in python ,I got following : 1.1 * 1.1 1.2102 why python get wrong result? Who can tell me where's the 0.0002 from? It's not a python errorIt's the nature of floating point arithm

Re: Floating point multiplication in python

2011-09-05 Thread Chris Rebert
On Mon, Sep 5, 2011 at 10:57 PM, xyz wrote: > hi all: > > As we know ,  1.1 * 1.1 is 1.21 . > But in python ,I got following : > 1.1 * 1.1 > 1.2102 > > why python get wrong result? It's not Python's fault per se, rather it's the inherent nature of binary floating-point arithmetic

Floating point multiplication in python

2011-09-05 Thread xyz
hi all: As we know , 1.1 * 1.1 is 1.21 . But in python ,I got following : >>> 1.1 * 1.1 1.2102 why python get wrong result? Who can tell me where's the 0.0002 from? -- http://mail.python.org/mailman/listinfo/python-list