Home > Article > Backend Development > PHP implements simple and high-precision PI method
This article is the continuation of the previous article [PHP implements dart throwing method to find PI, the stupidest but most interesting](http://www.yinqisen.cn/blog-676.html)
After talking about the stupidest thing, let’s talk about one more A more sophisticated method, the code is as follows:
~~~.php
// pi = 2 + 2/3 + 2/3*2/5 + 2/3*2/5*2/7 + ...
$pi = (double)2.0; $z = (double)2.0;
$a = 1; $b = 3;
while ($z > 0.0000000000001) {
$z *= $a / $b;
$pi += $z;
$b += 2;
$a++;
}
echo $pi."n";
echo "PHP PI() =>".pi(). "n";
~~~
The source code has been compared with the pi() function that comes with PHP, and the accuracy is consistent. So guess how the pi() function is implemented?