On Fri, Nov 05, 2010 at 05:40:39PM +0100, Arthur Bela wrote:
> Does anyone has a "generate-pi.c" source code?

Search for pi spigot algorithm.

Here is a tiny C program from Jeremy Gibbon's Unbounded Spigot paper
(due to Dik Winter and Achim Flammenkamp):

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;}

This produces the first 15,000 digits concisely, but is obfuscated.
If you need an unbounded number of digits, search out the spigot
algorithm papers.

Alex
_______________________________________________
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"

Reply via email to