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

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-20 12:45:01
Original
979 people have browsed it

本篇是继上一篇 [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()函数是如何实现的呢?
Copy after login

Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template