New version of Pi calculator, break the speed bound!

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.

Borwein's quartic convergence algorithm in 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

Anonymous's picture

[...] New version of Pi

[...] New version of Pi calculator, break the speed bound! [...]

Post new comment

  • Allowed HTML tags: <img> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <span> <fn>
  • Lines and paragraphs break automatically.
  • Use [fn]...[/fn] (or <fn>...</fn>) to insert automatically numbered footnotes.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. The supported tag styles are: <foo>, [foo].
  • Mathematical equations and graphs can be added between [tex] and [/tex], [graph] and [/graph] tags.
  • Textual smileys will be replaced with graphical ones.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
1 + 1 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
Honey Pot that kill bots