gpt4 book ai didi

java - JVM 上的浮点运算会在所有平台上给出相同的结果吗?

转载 作者:IT老高 更新时间:2023-10-28 20:24:21 25 4
gpt4 key购买 nike

我在多台机器上运行的应用程序中使用 Java,所有机器都需要获得相同的数学运算结果。使用 Java 的浮点原语是否安全?还是应该只使用定点数学库?

最佳答案

一般来说,不。但是,您可以使用 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.

关于java - JVM 上的浮点运算会在所有平台上给出相同的结果吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22335046/

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