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

java.lang.Math—is “within 1 ULP” exclusive or inclusive?

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?我知道使用相等比较对于双打几乎总是一个坏主意,所以我主要是出于好奇并且能够在人们做类似事情时指出他们的错误(或让他们放心)。

仅供参考,

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