你需要doubleToRawLongBits
而不是doubleToLongBits
.
doubleToRawLongBits
提取实际的二进制表示。 doubleToLongBits
没有,它首先将所有NaN
s 转换为默认值NaN
。
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));
输出:
7FF8000000000000
7FF8000000000000
7FF8000000000000
7FF8000000000100