I just came across the definition of NaN
in Double.class
. It says:
/**
* A constant holding a Not-a-Number (NaN) value of type
* {@code double}. It is equivalent to the value returned by
* {@code Double.longBitsToDouble(0x7ff8000000000000L)}.
*/
public static final double NaN = 0.0d / 0.0;
I know that according the Java specification these literals represent the same number: 0.0
, 0.0d
, and 0.0D
.
Also for other constants, they did not use the 'd' suffix:
public static final double POSITIVE_INFINITY = 1.0 / 0.0;
public static final double NEGATIVE_INFINITY = -1.0 / 0.0;
Why did they need to write the suffix d to the first part of 0.0 in NaN definition?
Was this on purpose or by chance?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…