Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

pi generation

by Pete_I (Beadle)
on Jan 29, 2006 at 03:09 UTC ( #526243=sourcecode: print w/replies, xml ) Need Help??
Category: text processing
Author/Contact Info Pete_I
Description: calculates the digits of pi to $ARGV[0] accurately
#generate $ARGV[0] digits of pi.
#the algorithm is here:
#written by Pete_I with help from BillN1VUX(from freenode)
#edited to make more efficient use of memory

use strict;
use warnings;
use Math::BigFloat;

my $DIGS = $ARGV[0] || 50;

my $pi = Math::BigFloat->new();
for(0 .. $DIGS) {
 $pi->badd( get_digit($_) );
print "\n", $pi->round($DIGS) . "\n";

sub get_digit {
 my $k = Math::BigFloat->new(shift);
 ( 1 / 16 ** $k ) *
  (4 / (8 * $k + 1))-
  (2 / (8 * $k + 4))-
  (1 / (8 * $k + 5))-
  (1 / (8 * $k + 6))

digits of pi to compare accuracy
Replies are listed 'Best First'.
Re: pi generation
by Bill_N1VUX (Initiate) on Feb 02, 2006 at 04:18 UTC
    Thanks Pete, that was a fun little project. I was happy to help since no one else on IRC seemed to notice your question and it interested me. It was a great experience for my first time on IRC. (I'd ignored IRC for longer than I ignored Perl 1..4. I'm not sure I have time to be a regular everywhere, but it was fun, so I'll be back.)

    My notes on how we fixed this program, and how it connects to other things, are on my journal

    In order to link a comment on your posting to my journal entry, I decided it was time to do a properly signed Monk posting -- so I had to re-create my twice-zombied ID and actually log in, so my first IRC session begats my first monkish scriptorium.

    The whole Perl Monks theme amuses me in a nostalgic sort of way, since in the seventies, my main D&D characters ran a religious order for fun and profit.

    So thanks for the opportunity!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://526243]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2020-10-21 02:22 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (212 votes). Check out past polls.