JVM lack of support for NaN vs scala Double.NaN

floating-point, java, jvm, jvm-languages, scala

Solution

The text you quote says there is no signaling NaN, not that there is no NaN.

The import is that floating-point operations in Java produce the expected values (including NaNs and infinities) but do not throw exceptions.

Problem

I recently read in the Java Virtual Machine Specification that the JVM does not support a NaN value, nor a way to signal overflow. I'm specifically referring to section 2.8.1 of the jvms 7, key differences between floating-point arithmetic supported by the JVM and IEEE 754, the bullet point which states: ``` "The floating-point operations of the Java Virtual Machine do not throw exceptions, trap, or otherwise signal the IEEE 754 exceptional conditions of invalid operation, division by zero, overflow, underflow, or inexact. The Java Virtual Machine has no signaling NaN value." ``` Am I miss-understanding this? In Scala (which relies on Java primitives in Bytecode to represent numeric types), and in Java's Double object, there is a NaN and a Positive/Negative Infinity value (which in Java have documented corresponding binary values). How are these handled efficiently if the JVM doesn't support them?

Original source