Note: Newer version of the pi calculation is here and a even more faster one here.
I want to release some Benchmark system can be uploaded to any web host and check how good the web hosting is. Pi (?) calculations spread widely as one of the most popular CPU benchmark system, that's why I have created a Pi calculator that can get to the accuracy you want. For now, there is still one thing I'm not sure yet, I will explain it after show you the code.
function bcpi($precision=30){
$accuracy = ($precision+5)*45/32;
//accuracy worked till the 180th $precision, almost used 30 second to calculate
bcscale($precision+5);
$n = 1;
$bcatan1 = 0;
$bcatan2 = 0;
while($n < $accuracy){
//atan functions
$bcatan1 = bcadd($bcatan1, bcmul(bcdiv(pow(-1, $n+1), $n * 2 - 1), bcpow(0.2, $n * 2 -1)));
$bcatan2 = bcadd($bcatan2, bcmul(bcdiv(pow(-1, $n+1), $n * 2 - 1), bcpow(bcdiv(1,239), $n * 2 -1)));
++$n;
}
return bcmul(4,bcsub(bcmul(4, $bcatan1),$bcatan2),5);
}
This Pi formula is not the fastest(converge speed), but it is one of the easiest. it uses Machin's formula + Taylor Series work together.
So, this is the BCMath version of atan() and pi() .
Why not use the original pi()? because from the statement of Keamos at gmail on 13-Jan-2006 09:31, it shows pi() have a precision limit. Note this script is very slow, and the time it need is increase squarely, so 100 precision could use up to 1 second.
Now, I have only one problem, the Pi's accuracy, Pi's accuracy are not the same as it's precision. Precision is the number of decimal it returns, the accuracy is the closeness to the real pi's value rounded the same precision. I want to output any precision with 100% accuracy, then I must find the relationship between two of them. You guessed it right, I don't know :aok:
Edit: it looks like precision:accuracy is somewhere around 45:32.
Just Added on 2007-01-20: cut off the last few numbers because it usually not 100% accurate
If anything know something about that, please tell me about it. Thanks in advance.
Recent comments
45 min 45 sec ago
16 hours 46 min ago
18 hours 19 min ago
2 days 16 hours ago
2 days 16 hours ago
2 days 16 hours ago
2 days 21 hours ago
3 days 5 hours ago
3 days 8 hours ago
4 days 16 hours ago