rec.puzzles Archive

How can I calculate many digits of pi?

analysis/calculate.pi Added material

Problem

How can I calculate many digits of pi?
Show solution
long a=10000,
    b,
    c=2800,
    d,e,
    f[2801],
    g;

main()
   {
    for (;b-c;) f[b++]=a/5;

    for (;
        d=0,g=c*2;
        c-=14, printf("%.4d",e+d/a), e=d%a)
        
    for (b=c;
         d+=f[b]*a,f[b]=d%--g,d/=g--,--b;
         d*=b);
   }

Additional material

[ Editor: from the rec.puzzles thread "Formulae for pi", November 1992. ]

This is the best algorithm I know for generating PI:

y0=SQRT(2) -1
a0=6-4*SQRT(2)

y1=(1-(1-y0^4)^(1/4))/(1+(1-y0^4)^(1/4))
a1=((1+y1)^4)*a0-(2^3)(y1(1+y1+(y1)^2)

y2=(1-(1-y1^4)^(1/4))/(1+(1-y1^4)^(1/4))
a2=((1+y2)^4)*a1-(2^5)(y2(1+y2+(y2)^2)

and so on ...

1/(a15) will give more than two billion digits of PI..

-- Ashraf Michail <amichail@r-node.gts.org>