Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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]
[Discipulus]: Tanktalus my comment was about how to fork & join in tk?
[marioroy]: Oh, I've might of missed Discipulus's earlier response. I had gone to bed.
[Tanktalus]: ah, I don't even have the perlmonks site open in my browser :)
Tanktalus is chatting through his cbstats application :)
[marioroy]: Perl is so much fun.
[Discipulus]: Tanktalus i recently started a Meditation about marioroy's MCE suit of modules, but is even better to see a practical question answered than responses to my meditation
[Discipulus]: good night mario!
[Tanktalus]: yeah, I saw you post about MCE - the concept looks really really cool. I wonder how well it plays with Coro :)
[Lady_Aleena]: Hi guys. I asked this earlier but got no answer. Why is this dying at -exec: my @music_times = qx(find ~/Music/Albums/ -type f -iname '*.mp3' -exec mp3info -p "%S\n" {} \;);
[Lady_Aleena]: The error find: missing argument to `-exec'

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2017-04-23 19:51 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (432 votes). Check out past polls.