Subject: | Missing BigFloat representation |
Here is a script I wrote that will produce an arbitrary number of digits of Tau. It would seem useful to have a higher precision version available, similar to Math::BigFloat's bpi (though for many digits this script is quite a bit faster than bpi's current implementation).
This could be in the examples directory, or have available as a function (e.g. tau_bigfloat($digits)).
Note that if you don't have Math::BigInt::GMP or Math::BigInt::Pari installed, it will be very slow as expected: 10k digits in 0.25 seconds using GMP backend, 5 minutes with Calc backend. This is not an issue if you just want 100 or so digits.
Subject: | tau.pl |
#!/usr/bin/env perl
use warnings;
use strict;
use Math::BigFloat try=>"GMP,Pari";
my $digits = shift || 100;
# Produce a given number of digits of Tau (2*Pi) using AGM method.
# Dana Jacobsen, 2013.
my $acc = $digits+8;
my $HALF = Math::BigFloat->new("0.5");
my ($an, $bn, $tn, $pn) = (Math::BigFloat->bone, $HALF->copy->bsqrt($acc),
$HALF->copy->bmul($HALF), Math::BigFloat->bone);
while ($pn < $acc) {
my $prev_an = $an->copy;
$an->badd($bn)->bmul($HALF, $acc);
$bn->bmul($prev_an)->bsqrt($acc);
$prev_an->bsub($an);
$tn->bsub($pn * $prev_an * $prev_an);
$pn->badd($pn);
}
$an->badd($bn);
$an->bmul($an,$acc)->bdiv(2*$tn, $digits);
print "$an\n";