Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #12887

Re: Floating point multiplication in python

From Gelonida N <gelonida@gmail.com>
Subject Re: Floating point multiplication in python
Date 2011-09-07 10:57 +0200
References <mailman.790.1315289581.27778.python-list@python.org> <j44rre$e4c$1@r03.glglgl.eu> <2204592.egLE2XKegd@PointedEars.de> <4e66f843$0$29969$c3e8da3$5496439d@news.astraweb.com>
Newsgroups comp.lang.python
Message-ID <mailman.827.1315385890.27778.python-list@python.org> (permalink)

Show all headers | View raw


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 = 11/56294995342131200
> 
> So we can conclude that, at least for 1.1**2, Python floats are more
> accurate than we would expect from a simple application of the binomial
> theorem. (For implementations using IEEE doubles.)


The reason why the error is different from the 2*a*e is, that we
encounter two problems.

first problem is, that x = a + e
e exists because a float does have a limited number (let's call it N) of
digits and a has an infinite amount of non zero digits in the binary format.


second problem is, that the result of the multiplication is not

(a+e) * (a+e) but a 'rounded' version of it, because the floating point
representation of the result would require about 2*N digits, whereas
only N digits will be stored in the result.

depending on the rounding which happened (up or down) the error will be
bigger or smaller than the estimated one.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Floating point multiplication in python xyz <xyzhtml@163.com> - 2011-09-06 13:57 +0800
  Re: Floating point multiplication in python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-09-06 17:11 +1000
  Re: Floating point multiplication in python Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2011-09-06 12:14 +0200
    Re: Floating point multiplication in python Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-09-06 18:07 +0200
      Re: Floating point multiplication in python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-09-07 14:51 +1000
        Re: Floating point multiplication in python Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2011-09-06 23:35 -0700
        Re: Floating point multiplication in python Gelonida N <gelonida@gmail.com> - 2011-09-07 10:57 +0200
        Re: Floating point multiplication in python Terry Reedy <tjreedy@udel.edu> - 2011-09-07 05:37 -0400

csiph-web