在所有平台上,JVM上的浮点运算是否会得到相同的结果? [英] Will floating point operations on the JVM give the same results on all platforms?
问题描述
strictfp
表达式:$ b
在FP-strict表达式中,所有的中间值必须是浮点值集合或双值集合的元素,意味着所有FP-strict表达式的结果都必须是IEEE 754算法用单一格式和双格式表示的操作数预测的结果。
在不是FP严格的表达式中,某些实现使用扩展指数范围来表示中间结果;总的来说,净效应是,在独占使用浮点值集或双值集可能导致上溢或下溢的情况下,计算可能产生正确答案。
I'm using Java in an application running on multiple machines, and all machines need to get the same results for mathematical operations. Is it safe to use Java's floating point primitives? Or should I just use a fixed-point math library?
Not in general, no. However, you can use strictfp
expressions:
Within an FP-strict expression, all intermediate values must be elements of the float value set or the double value set, implying that the results of all FP-strict expressions must be those predicted by IEEE 754 arithmetic on operands represented using single and double formats.
Within an expression that is not FP-strict, some leeway is granted for an implementation to use an extended exponent range to represent intermediate results; the net effect, roughly speaking, is that a calculation might produce "the correct answer" in situations where exclusive use of the float value set or double value set might result in overflow or underflow.
这篇关于在所有平台上,JVM上的浮点运算是否会得到相同的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!