我刚刚看到了NaNin 的定义Double.class.它说:
/**
* 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;
Run Code Online (Sandbox Code Playgroud)
我知道,根据Java规范这些文字代表了同一个号码:0.0,0.0d,和0.0D.
另外对于其他常量,他们没有使用'd'后缀:
public static final double POSITIVE_INFINITY = 1.0 / 0.0;
public static final double NEGATIVE_INFINITY = -1.0 / 0.0;
Run Code Online (Sandbox Code Playgroud)
为什么他们需要在NaN定义中将后缀d写入0.0的第一部分?
这是故意的还是偶然的?
java ×1