0

I saw a pi calculate algorithm on a website and it looks like that:

#include <stdio.h>
int a[52514],b,c=52514,d,e,f=1e4,g,h;
main(){
 for(;b=c-=14;h=printf("%04d",e+d/f)){
    for(e=d%=f;g=--b*2;d/=g){
        d=d*b+f*(h?a[b]:f/5);
        a[b]=d%--g;}
   }
}

it was said this code was based on this expansion,but i do not understand the relative between the code and the expansion.

pi= sigma( (i!) ^2*2^(i+1))/(2i+1)! (i=0 to infinite)

Could you help me explain it?Thanks.

ameyCU
  • 16,489
  • 2
  • 26
  • 41
Page David
  • 1,309
  • 2
  • 14
  • 25
  • 2
    throw in a macro or two and you have an IOCCC winner, if not already. – Plopperzz Oct 31 '15 at 03:41
  • @Plopperzz so what is macro means?and what should I do? – Page David Oct 31 '15 at 04:07
  • 1
    take a look at this post [here](http://stackoverflow.com/questions/20287513/can-anyone-make-heads-or-tales-of-this-spigot-algorithm-code-pitiny-c), which also mentions the [Spigot Algorithm](https://en.wikipedia.org/wiki/Spigot_algorithm). funny, I was the 314th viewer of that post. – Plopperzz Oct 31 '15 at 04:14
  • @Plopperzz thanks,it is really hard to understand. – Page David Oct 31 '15 at 04:35
  • @Plopperzz Now I know how the code run,but I can not understand why it equals to the expansion.i think there is no reason it print the digits of pi. – Page David Oct 31 '15 at 05:41

1 Answers1

1
pi+3=sigma( (m!)^2 * 2^m * m / (2*m)! ) (m=1 to infinite).

Algorithm's S Pflouffe use it.

V. Michel
  • 1,599
  • 12
  • 14