PHP: Calculate Pi, revisited

Note: Even Faster pi calculation is here
The Pi calculation system I released previously was very slow, 180 digits could cost about 30 seconds. That's why I have to release a much faster system.
Especially after I find out that Yonatan Naamad have produced a faster script that calculate 200 digits of pi in 10 seconds.
So here is the newest release of bcpi, it generated 1000 digits of pi in 5 seconds! Should be the fastest one alive. Why is it fast? well it follows Chudnovsky brothers's Chudnovsky algorithm.
The Chudnovsky algorithm
Each time k plus one, 14 of pi's digit will be find, so this is much more efficient than the old one.
The new function:

function bcfact($n){
  return ($n == 0 || $n== 1) ? 1 : bcmul($n,bcfact($n-1));
}
function bcpi($precision){
	$num = 0;$k = 0;
	bcscale($precision+3);
$limit = ($precision+3)/14;
while($k < $limit){
	$num = bcadd($num, bcdiv(bcmul(bcadd('13591409',bcmul('545140134', $k)),bcmul(bcpow(-1, $k), bcfact(6*$k))),bcmul(bcmul(bcpow('640320',3*$k+1),bcsqrt('640320')), bcmul(bcfact(3*$k), bcpow(bcfact($k),3)))));
	++$k;
}
return bcdiv(1,(bcmul(12,($num))),$precision);
}

[...] PHP: Calculate Pi,

[...] PHP: Calculate Pi, revisited [...]

[...] PHP: Calculate Pi,

[...] PHP: Calculate Pi, revisited [...]

Post new comment

The content of this field is kept private and will not be shown publicly.
If you have a Gravatar account, used to display your avatar. If you have a Gravatar account, used to display your avatar.
  • Allowed HTML tags: <img> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <span> <fn>
  • Lines and paragraphs break automatically.
  • Textual smileys will be replaced with graphical ones.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".
  • Use [fn]...[/fn] (or <fn>...</fn>) to insert automatically numbered footnotes.

More information about formatting options

What is 31 + 42?
To combat spam, please solve the math question above.
Honey Pot that kill bots