gpt4 book ai didi

java - 在 Java 中,为了一致性,StrictMath 仍然优于 Math 吗?

转载 作者:行者123 更新时间:2023-12-01 22:04:53 26 4
gpt4 key购买 nike

我知道 StrictMath 遵循给定的算法,并且会在每台机器上给出相同的结果;然而,数学更准确,而且我发现它被更多地使用。哪个是首选?显然,我想要可重复性,但准确性对我来说也很重要。

最佳答案

基于 accuracy 的真实定义,StrictMath 更准确。一般来说,MathStrictMath 更快,但情况并非总是如此;通常,Math 库函数只是调用 StrictMath 实现。

无论如何,我认为您的问题的答案可以直接从 Math 找到。 Javadoc:

Unlike some of the numeric methods of class StrictMath, all implementations of the equivalent functions of class Math are not defined to return the bit-for-bit same results. This relaxation permits better-performing implementations where strict reproducibility is not required.

By default many of the Math methods simply call the equivalent method in StrictMath for their implementation. Code generators are encouraged to use platform-specific native libraries or microprocessor instructions, where available, to provide higher-performance implementations of Math methods. Such higher-performance implementations still must conform to the specification for Math.

对于大多数应用程序来说,通用的 Math 库是更好的选择。如果需要考虑非常小的舍入误差,则需要使用 StrictMath。因此,除非您的准确性必须非常高,否则不要因为不一致而陷入困境。

关于java - 在 Java 中,为了一致性,StrictMath 仍然优于 Math 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32977034/

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