Home >Backend Development >PHP Tutorial >PHP实现简单高精度的求PI方法

PHP实现简单高精度的求PI方法

WBOY
WBOYOriginal
2016-06-20 12:45:01933browse

本篇是继上一篇 [PHP实现投镖求PI法,最笨但最有意思](http://www.yinqisen.cn/blog-676.html)讲完最笨的,再说一个更精巧的方法,代码如下:~~~.php<?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";~~~源码中和PHP自带的pi()这个函数做了对比,精度一致,那猜猜pi()函数是如何实现的呢?

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn