which pi formula is given in the decimal module documentation?

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Mon Dec 21 23:02:57 EST 2009


En Mon, 21 Dec 2009 17:40:40 -0300, Albert van der Horst  
<albert at spenarnc.xs4all.nl> escribió:
> In article <kv0dvx.7k5 at spenarnc.xs4all.nl>,
> Albert van der Horst  <albert at spenarnc.xs4all.nl> wrote:
>> In article  
>> <a266b155-02df-4294-8b91-41be4a1e4f81 at a32g2000yqm.googlegroups.com>,
>> Mark Dickinson  <dickinsm at gmail.com> wrote:
>>>
>>> After a cup of coffee, it's much clearer:  this just comes from the
>>> Taylor series for arcsin(x), applied to x = 1/2 to get asin(1/2) =  
>>> pi/6.

> Below you see cos which just calculates cosine with a
> Taylor series.
> Then there is pi2() that uses it to calculate pi, for the
> normal fp precision.
> pi3() shows the algorithm in its glory and should work for
> any floating point package.
> pi4() does the same, if precision is given.
> And last but not least pi5() that uses the Decimal package
> to advantage. It precalculates a starting point in 1/5 of
> the precision. Then it does one more iteration in the full precision.
> For 1000 digits it is about 5 times faster than pi(), for
> a moderate increase in complexity.

You may try Demo/scripts/pi.py in the source distribution; it uses long  
integers to compute a continued fraction approximation to pi. I wonder how  
does it compare to those other algorithms.

-- 
Gabriel Genellina




More information about the Python-list mailing list