#!/usr/bin/perl -w use strict; use warnings; use constant ITERS => 13; use Math::BigFloat; Math::BigFloat->precision(-10000); my $x = Math::BigFloat->new("2.0")->fsqrt; my $p = $x + 2; my $y = ($x+0)->fsqrt; for(1 .. ITERS) { my $xroot = ($x+0)->fsqrt; $x = ($xroot + 1/$xroot)/2; $xroot = ($x+0)->fsqrt; $p = $p * (($x + 1)/($y + 1)); $y = (($y * $xroot) + (1/$xroot))/($y + 1); print "Iter $_ $p\n\n"; }