IEEE-754 Float64中PI最准确的近似值?
IEEE-754 Float64中最准确的PI近似值是什么?
FWIW似乎同时使用JavaScript和PHP使用3.1415926535897931159979979634685444185161590576171875
,这可能是答案,我不知道。
what is the most accurate approximation of pi possible in IEEE-754 float64?
fwiw it seems both Javascript and PHP use 3.141592653589793115997963468544185161590576171875
, which might be the answer, i don't know.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,3.141592653589793115997963468544185161590576171875是IEEE-754 binary64 1 1 数字。它也可以写入十六进制的浮点数常数,
0x1.921fb544442d18p1
。 (我保留0x3.243F6A8888888D313198A2E03707344AP0L
也要具有更宽的格式的值。 ,并且不需要小数点浮点数常数,因此,当您使用十六进制形式时,您可能更有可能获得正确的结果。脚注
1 IEEE-754 2008使用标准的64位基底两种格式使用“ binary64”。它也称为“双重精度”。一些编程语言可能称其为
float64
或float64
。Yes, 3.141592653589793115997963468544185161590576171875 is the IEEE-754 binary641 number closest to π. It can also be written as a hexadecimal floating-point constant,
0x1.921fb54442d18p1
. (I keep0x3.243f6a8885a308d313198a2e03707344ap0L
on hand to have the value for wider formats as well.) The C standard requires C implementations that use a base-two floating-point format to correctly round hexadecimal floating-point constants, and it does not require that for decimal floating-point constants, so you may be more likely to get a correct result when you use the hexadecimal form.Footnote
1 IEEE-754 2008 uses “binary64” for the standard 64-bit base-two format. It is also called “double precision.” Some programming languages might call it
float64
orFloat64
.@Eric是正确的,IEEE-754-BINARY64 PI大约0.000000000000000001低于Real Pi,而下一个可能的增量为IEEE-754-Binary64大约0.0000000000000003高于真实PI,这是两者相同的零数量,16个零是相同的零数, 3大于1,这意味着Eric+JavaScript+PHP是正确的。证明这一点的PHP测试代码:
0.000000000000000000000000000000000000000000000000000000000001
/code>是最低的增量,实际上有任何不同。如果我在这个假设中错了,则设置更低的增量可能会显示出不同的数字! (我没有足够的CPU+耐心来舒适地测试任何较低的增量。)
输出:
@Eric is correct, IEEE-754-binary64 pi is approximately 0.0000000000000001 lower than real pi, and the next possible increment to IEEE-754-binary64 is approximately 0.0000000000000003 higher than real pi, that's the same number of zeroes for both, 16 zeroes, and 3 is more than 1, which means Eric+Javascript+PHP are all right. PHP test code to prove it:
0.000000000000000000000001
is the lowest increment that actually makes any difference. if i'm wrong in this assumption, setting an even lower increment might reveal a different number! (i don't have enough cpu+patience to comfortably test any lower increments..)output: