#!/usr/bin/perl use strict; use constant ITERS => 6; use Math::BigFloat; my $x = Math::BigFloat->new("2.0")->fsqrt; my $p = $x + 2; my $y = $x->fsqrt; for(1 .. ITERS) { my $xroot = $x->fsqrt; $x = ($xroot + 1/$xroot)/2; $xroot = $x->fsqrt; $p = $p * (($x + 1)/($y + 1)); $y = (($y * $xroot) + (1/$xroot))/($y + 1); print "$p\n\n"; }
In reply to Arithmetic-Geometric Mean calculation of pi. by rpc
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |