You think use PHP to calculate the 2000 places after pi in 8 seconds is fast? you haven't see anything yet. This is the 3rd last attempt of finding pi (at least till 2020). I still have 2 more algorithms going to try. This one uses Borwein's quartic convergence algorithm on pi finding.
You want to know the speed right? It uses less than 4 second to find the 2000th place of pi! and it is only slightly slower than the older pi calculator when precision is very low(between 1 to 30).
Feel free to check the source.
This was modified to be part of the BCext class I am working on right now.
function bcpi($precision){ bcscale($precision+6); $a = bcsqrt(2); $b = 0; $p = bcadd(2, $a); $i = 0; $count = ceil(log($precision+6)/log(2))-1; while($i < $count){ $sqrt_a = bcsqrt($a); $a1 = $a; $a = bcdiv(bcadd($sqrt_a,bcdiv(1,$sqrt_a)),2); $b_up = bcmul($sqrt_a,bcadd(1,$b)); $b_down = bcadd($a1,$b); $b = bcdiv($b_up, $b_down); $p_up = bcmul(bcmul($p,$b),bcadd(1,$a)); $p_down = bcadd(1, $b); $p = bcdiv($p_up, $p_down); ++$i; } return bcadd($p,0,$precision); }
Comments
[...] New version of Pi
[...] New version of Pi calculator, break the speed bound! [...]
Post new comment