求 pi 的值直到 50 位
我想计算 PI 的值直到 50 位。
如何在java中实现小数点后50位?
I want to calculate the value of PI till 50 digits.
How to do this in java for 50 decimal places?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您无法使用默认数据类型执行此操作,因为您需要 50 位数字:50 / log(2) * log(10) = 166 位。这里 BigDecimal 是您可以使用的一种类型。但您应该记住,22/7 只是 pi 的近似值,要得到正确的 50 位数字,您需要更好的公式(例如蒙特卡洛方法、泰勒级数……)。
You cant do that with default data types, as you need for 50 digits: 50 / log(2) * log(10) = 166 bits. Here BigDecimal is one type you could use instead. But you should have in mind, that 22/7 is just an approximation of pi, and to get it right for 50 digits you need much better formula (e.g. Monte-Carlo method, taylor series, ...).
您正在使用双精度变量,而应该使用精度更高的变量。查看 BigDecimal 类。
You are using a double variable and instead should use something that has a greater precision. Look into the
BigDecimal
class.输出为
计算得出的 pi(约 1000 项和 50 位小数):3.14059265383979292596359650286939597045138933077984
实际圆周率:3.141592653589793
The output is
Calculated pi (approx., 1000 terms and 50 Decimal Places): 3.14059265383979292596359650286939597045138933077984
Actual pi: 3.141592653589793
以下是 Bailey、Borwein 和 Plouffe 的突破性论文:http://oldweb. cecm.sfu.ca/projects/pihex/p123.pdf
与此同时,发现了更快的公式(遵循相同的原理):http://en.wikipedia.org/wiki/Bellard%27s_formula
Here is the break through paper of Bailey, Borwein and Plouffe: http://oldweb.cecm.sfu.ca/projects/pihex/p123.pdf
In the meantime, even faster formulas (following the same principles) were found: http://en.wikipedia.org/wiki/Bellard%27s_formula
这是 Bellard 公式 bigPi(200,2000) 的快速而肮脏的实现,适用于 75 毫秒内超过 500 位小数。
This is a quick and dirty implementation of Bellard's formula bigPi(200,2000) is good for over 500 decimal places in 75ms.