gpt4 book ai didi

java.lang.Math—— “within 1 ULP” 是独占还是包含?

转载 作者:搜寻专家 更新时间:2023-11-01 02:05:29 25 4
gpt4 key购买 nike

java.lang.Math 文档说明了很多函数,例如 Math.pow :

The computed result must be within 1 ulp of the exact result.

但我一直没能找到这到底是什么意思。是排他性的还是包容性的?换句话说,如果确切的结果可以用 double 表示,返回值是否包含准确的结果,或者它仍然可能偏离 1 ULP?

例如,我们可以依赖 Math.pow(3.0, 2.0) == 9.0 吗?我知道使用相等比较对于 double 几乎总是一个坏主意,所以我主要是出于好奇并且能够在人们做类似事情时指出他们的错误(或让他们放心)。

最佳答案

仅供引用,

The quality of implementation specifications concern two properties, accuracy of the returned result and monotonicity of the method. Accuracy of the floating-point Math methods is measured in terms of ulps, units in the last place. For a given floating-point format, an ulp of a specific real number value is the distance between the two floating-point values bracketing that numerical value. When discussing the accuracy of a method as a whole rather than at a specific argument, the number of ulps cited is for the worst-case error at any argument. If a method always has an error less than 0.5 ulps, the method always returns the floating-point number nearest the exact result; such a method is correctly rounded. A correctly rounded method is generally the best a floating-point approximation can be; however, it is impractical for many floating-point methods to be correctly rounded.

Instead, for the Math class, a larger error bound of 1 or 2 ulps is allowed for certain methods. Informally, with a 1 ulp error bound, when the exact result is a representable number, the exact result should be returned as the computed result; otherwise, either of the two floating-point values which bracket the exact result may be returned.

For exact results large in magnitude, one of the endpoints of the bracket may be infinite. Besides accuracy at individual arguments, maintaining proper relations between the method at different arguments is also important. Therefore, most methods with more than 0.5 ulp errors are required to be semi-monotonic: whenever the mathematical function is non-decreasing, so is the floating-point approximation, likewise, whenever the mathematical function is non-increasing, so is the floating-point approximation. Not all approximations that have 1 ulp accuracy will automatically meet the monotonicity requirements.

Source

关于java.lang.Math—— “within 1 ULP” 是独占还是包含?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35658665/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com