среда, 25 февраля 2009 г.

virtual escalation of pi sequence

If we imagine some virtual escalation of PI sequence to other levels of abstraction, what kind of
model it will be?

#!/usr/bin/perl
###
#generate $ARGV[0] digits of pi.
#the algorithm is here:
#http://crd.lbl.gov/~dhbailey/
####
#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;
Math::BigFloat->div_scale($DIGS+10);
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))
)
}

Комментариев нет:

Отправить комментарий