I stumbled on a neat bit of C code when looking at the PB-2000C (a C-capable calculator, which is weird enough by itself). The code calculates Pi to any number of places. Here's it is...
long a=10000,b,c,d,e,*f,g;
main(){printf("digits?");scanf("%ld",&c);c*=3.5;c-=c%14;f=malloc(4*c+4);
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);}
Compiled and ran it on my machine. I don't understand how it works, but it does. Could anyone with a bit of math skills please comment on what's actually happening here? It looks like magic to me.
Thanks
A