Java 浮点原语是否有任何 IEEE 754 标准实现?

Is there any IEEE 754 standard implementations for Java floating point primitives?

我对 Java 是否使用 IEEE 754 标准来实现其浮点运算感兴趣。 Here 我在文档中看到了这种东西:

operation defined in IEEE 754-2008

据我所知,IEEE 754 的积极方面是提高浮点运算的精度,因此如果我在 Java 中使用 doublefloat,计算的前提是相同的如 BigDecimal?如果不是,那么在 Math class 中使用 IEEE 754 标准有什么意义?

I'm interested if Java is using IEEE 754 standard for implementing it's floating point arithmetic.

IEEE-754 定义了多个 浮点类型的标准。多年来,它们都是二进制浮点数;这就是 Java 的 floatdouble 是: float 是一个 32 位 IEEE-754 二进制浮点值(标准称 binary32). double is a 64-bit one (what the standard calls binary64). These binary floating point numbers are very efficient for computers to calculate, but because they work in binary and we work in decimal, there are some expectation mismatches; for instance, 0.1 cannot be stored precisely in a double, and you get oddities like 0.1 + 0.2 turning out to be 0.30000000000000004. See Is floating point math broken? 为细节。例如,它们不是财务计算的好选择。

BigDecimal 是一个 Java class,它以任意精度实现 十进制 小数。它比使用 double 慢得多,但结果符合我们对小数的期望(例如,0.1 + 0.2 将是 0.3)。

2008 版 IEEE-754 添加了重要的新格式,特别是 decimal32, decimal64, and decimal128。这些是 decimal 浮点数,因此它们的工作方式与我们相同。 0.1可以准确存入decimal640.1 + 0.2decimal64 中的 0.3。但是,据我所知,它们与您的问题并不相关。

由于 BigDecimal 早于 IEEE-754 2008(在一定程度上),它定义了自己的语义。

And if not than what's the point of using IEEE 754 standard in Math class?

JDK9 向 Math 添加了新操作,这些操作执行 IEEE-754 2008 规范定义的操作(例如 fma, which does a fused multiply-add),因此它参考 IEEE-754 2008 定义了这些操作规格,为清楚起见。

更多阅读: