PHP 中如何将 pi 计算为指定位数?
如何在 PHP 中计算 pi 的值,最多 X 个十进制数字。
小数点后 4 位
3.141
64 位小数
3.141592653589793238462643383279502884197169399375105820974944592
How can I calculate the value of pi in PHP up to X decimal numbers.
4 decimal points
3.141
64 decimal points
3.141592653589793238462643383279502884197169399375105820974944592
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
找到@Konamiman 发布的损坏链接的来源。
将结果与:http://www.angio.net/pi/digits/50 进行比较。 txt 并且它们是相同的。
Found the source for the broken link @Konamiman posted.
Compared the results to: http://www.angio.net/pi/digits/50.txt and they are the same.
在php中计算PI?
当我们已经有了
M_PI
常量时,为什么还要进行计算呢?M_PI
包含值3.14159265358979323846
。对于 PI 来说,10000 位小数是一个相当大的数字。
请参阅:http://www.php.net/manual/en/math。常量.php
Calculating PI in php?
Why calculate when we already have the
M_PI
constant?M_PI
contains the value3.14159265358979323846
.10000 decimal places for PI is quite a number.
See: http://www.php.net/manual/en/math.constants.php
您可以通过 Chudnosky 级数计算 Pi。如果您的服务器具有非常高的内存,您可以轻松地将 Pi 计算到许多小数位。如果您想将其获取到某个特定的小数位,请将努力增加到一个非常大的数字并使用 substr 将其缩短到所需的小数位。如果你觉得这个过程很慢,那么你可以通过google搜索得到pi值。
You can calculate Pi by the Chudnosky series. If you have a server with a very high ram you can easily calculate Pi to many decimal places. If you want to get it to some specific decimal place then, increase the efforts to a really large number and use substr to shorten it to your required decimal place. If you think this process is very slow, then you can get pi value by searching it on google.
据我所知,PHP 无法保存那么长的数字,但 22/7 是一种计算 PI 的古老方法,尽管这不会比 PHP 中包含的 PI 常数更好。也许您正在尝试输出一长串 PI 作为练习。
PHP cannot hold a number that long as far as I know, but 22/7 is an ancient way to calculate PI, though that will not be any better than the PI constant included in PHP. Perhaps you are trying to output a long string of PI as an exercise.