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
", Double.doubleToLongBits(n));
System.out.printf("%X
", Double.doubleToRawLongBits(n));
System.out.printf("%X
", Double.doubleToLongBits(n2));
System.out.printf("%X
", Double.doubleToRawLongBits(n2));
output:
7FF8000000000000
7FF8000000000000
7FF8000000000000
7FF8000000000100
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…