java.lang.Math和java.lang.StrictMath之间有什么区别? [英] What's the difference between java.lang.Math and java.lang.StrictMath?

查看:140
本文介绍了java.lang.Math和java.lang.StrictMath之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

显然 java.lang .StrictMath 包含其他函数(双曲线等) java.lang.Math 没有,但是两个库中的函数有区别吗?

Obviously java.lang.StrictMath contains additional functions (hyperbolics etc.) which java.lang.Math doesn't, but is there a difference in the functions which are found in both libraries?

推荐答案

Math 类提供了两个类之间差异的一些信息:

The Javadoc for the Math class provides some information on the differences between the two classes:



class StrictMath 的某些数值方法不同,所有实现$ b $类
的等价函数的b 数学未定义为返回
逐位相同的结果。这个
放宽允许更好的
实现,其中不需要严格的
再现性。

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.

默认情况下,许多 Math 方法
只需在
StrictMath 中调用等效方法即可实现。
鼓励代码生成器使用
特定于平台的本机库或
微处理器指令,其中
可用,以提供
更高性能的
实现数学方法。这种性能更高的
实现仍然必须符合
Math 的规范。

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 类列出了一些关于某些操作应该做什么的规则,但它们不要求完全在库的所有实现中都返回相同的结果。

Therefore, the Math class lays out some rules about what certain operations should do, but they do not demand that the exact same results be returned in all implementations of the libraries.

这允许库的特定实现返回类似的,但不是完全相同的结果,例如,例如,调用 Math.cos 类。这将允许特定于平台的实现(例如使用x86浮点,例如,SPARC浮点),这可能会返回不同的结果。

This allows for specific implementations of the libraries to return similiar, but not the exact same result if, for example, the Math.cos class is called. This would allow for platform-specific implementations (such as using x86 floating point and, say, SPARC floating point) which may return different results.

(请参阅软件实施部分。有关平台特定实现的一些示例,请参阅维基百科中的org / wiki / Sinerel =noreferrer>正弦文章。)

(Refer to the Software Implementations section of the Sine article in Wikipedia for some examples of platform-specific implementations.)

但是,使用 StrictMath ,不同实现返回的结果必须返回相同的结果。对于需要在不同平台上重现结果的情况,这是理想的。

However, with StrictMath, the results returned by different implementations must return the same result. This would be desirable for instances where the reproducibility of results on different platforms are required.

这篇关于java.lang.Math和java.lang.StrictMath之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆