[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] algorithm to calculate pi



		       On Mon, 26 Jun 2000 00:39:41 PDT,
			      "Perl lover" wrote:

:This is silimar to my first try on Math::BigFloat, but it actually
:gave wrong output:

Oops.  I guess we need more BigFloats.  Here's one that works for
280 digits, although it takes about 20 seconds to run on a Sun E420R:

	use Math::BigFloat;
	$Math::BigFloat::div_scale = 281;
	my $i=0;
	my @p16 = ();
	$p16[0] = new Math::BigFloat 1;
	my $pi = new Math::BigFloat 0;

	for(0..280){
	   my $t1=new Math::BigFloat 4;
	   my $t2=new Math::BigFloat 2;
	   my $t3=new Math::BigFloat 1;
	   my $t4=new Math::BigFloat 1;
	   $t1 /= $i+1;
	   $t2 /= $i+4;
	   $t3 /= $i+5;
	   $t4 /= $i+6;
	   $pi += $p16[$_]*($t1-$t2-$t3-$t4);
	   $i  += 8;
	   $p16[$_+1] = $p16[$_]/16;
	}

Michael

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe