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

RE: Re: [FWP] algorithm to calculate pi



please run the following instead:

note i changed div_scale to 1000 to get more numbers..it runs
much faster.. and why it's even more accurate??!! (till 560th
digits).. if i change div_scale to 1000 in your code.. i got
only 400 accurate digits... i wonder why...


use Math::BigFloat; 
                      $Math::BigFloat::div_scale = 1000; 
                      my $i=0; 
                      my $p16 = new Math::BigFloat 1; 
                      my $pi = new Math::BigFloat 0; 

                      for(0..1000){ 
                      

my $t1 = ($i+4)*($i+5)*($i+6)*4-($i+1)*($i+5)*($i+6)*2-($i+1)*($i+4)*($i+6)-($i+1)*($i+4)*($i+5); 
                      my $t2 = ($i+1)*($i+4)*($i+5)*($i+6); 
                      $pi += ($p16*$t1)/$t2; 
                      $i  += 8; 
                      $p16/= 16; 
                      } 






>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




------------------------------------------------------------
Email account furnished courtesy of AntiOnline - http://www.AntiOnline.com
AntiOnline - The Internet's Information Security Super Center!



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