哪个更准确? java.lang.Math.E或Math.exp(1.0) [英] Which is more accurate? java.lang.Math.E or Math.exp(1.0)

查看:79
本文介绍了哪个更准确? java.lang.Math.E或Math.exp(1.0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过阅读Javadocs,我发现Math.E是"比任何其他值都更接近自然对数底数e的双精度值.". Math.E的打印值是2.718281828459045,而Math.exp(1.0)的值应该是相同的值:2.7182818284590455(末尾再加5).

Reading the Javadocs, I see that Math.E is "The double value that is closer than any other to e, the base of the natural logarithms.". The printed value for Math.E is 2.718281828459045 while the value of Math.exp(1.0), which should be the same value is: 2.7182818284590455 (one more 5 at the end).

在文档中,听起来好像Math.E中的位已被手动调整",以使其比Math.exp(1.0)产生的计算更接近e的实际值.这是正确的吗,还是我阅读的文档不正确?

From the docs, it sounds like the bits in Math.E have been "manually adjusted" to get closer to the actual value of e than the calculation produced by Math.exp(1.0). Is this correct, or am I reading the docs incorrectly?

如果这是正确的,那么使用Math.pow(Math.E,n)是否比Math.exp(n)更准确或更小?我已经用Google搜索并搜索过,但是在此特定问题上找不到任何东西.

If that is correct, then is using Math.pow(Math.E, n) more accurate than Math.exp(n), or less? I've Googled and search SO, but can't find anything on this particular issue.

推荐答案

小数点后16位的实际值为2.7182818284590452; 2比0更接近0,因此常数更接近.

The actual value to 16 decimal places is 2.7182818284590452; 2 is closer to 0 than to 5, so the constant is closer.

请注意,当使用任意一个数字进行浮点计算时,答案的浮点表示形式中的错误很可能会使您使用哪个 不相关的.

Note that when doing floating point calculations with either number it's quite likely the error in the floating point representation of your answer will make which one you use largely irrelevant.

这篇关于哪个更准确? java.lang.Math.E或Math.exp(1.0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆