Perl Monk, Perl Meditation  
PerlMonks 
Re: Computing pi to multiple precisionby moritz (Cardinal) 
on Sep 09, 2012 at 14:45 UTC ( #992590=note: print w/ replies, xml )  Need Help?? 
Ever since I've read about them, I've been fascinated by spigot algorithms for producing digits of pi. The basic idea for those algorithms is that most "interesting" transcendental numbers (like pi, e, ln(2)) have a pretty simple representation if the base is allowed (in a regular pattern) for each digit. Then the task of computing the first $N first digits is just that of a base conversion. And the fascinating part is that you can work with integers only To stay a bit on topic, I've ported this C implementation of a spigot algorithm for pi to Perl 6:
Since Rakudo is still pretty slow for this kind of stuff, I've traded a bit of readabilty for speed by using a native int in the inner loop, which means that Rakudo can inline most operators, but means I have to write $i = $i  1 instead of $i (because native ints are value types, and you cannot (yet?) pass them as writable values to routines, so the  operator cannot work on them).
In Section
Meditations

