What are the other NaN values?

floating-point, ieee-754, java, nan

Solution

You need `doubleToRawLongBits` rather than `doubleToLongBits`.

`doubleToRawLongBits` extracts the actual binary representation. `doubleToLongBits` doesn't, it converts all `NaN`s to the default `NaN` first.

double n = Double.longBitsToDouble(0x7ff8000000000000L); // default NaN
double n2 = Double.longBitsToDouble(0x7ff8000000000100L); // also a NaN, but M != 0

System.out.printf("%X\n", Double.doubleToLongBits(n));
System.out.printf("%X\n", Double.doubleToRawLongBits(n));
System.out.printf("%X\n", Double.doubleToLongBits(n2));
System.out.printf("%X\n", Double.doubleToRawLongBits(n2));

output:

7FF8000000000000
7FF8000000000000
7FF8000000000000
7FF8000000000100

Problem

The documentation for `java.lang.Double.NaN` says that it is A constant holding a Not-a-Number (NaN) value of type `double`. It is equivalent to the value returned by `Double.longBitsToDouble(0x7ff8000000000000L)`. This seems to imply there are others. If so, how do I get hold of them, and can this be done portably? To be clear, I would like to find the `double` values `x` such that ``` Double.doubleToRawLongBits(x) != Double.doubleToRawLongBits(Double.NaN) ``` and ``` Double.isNaN(x) ``` are both true.

Original source