The public static final double NaN field is set to 0.0d / 0.0 which should evaluate to 0x7ff8000000000000L if the JVM does implement it that way.
Division of a zero by a zero results in NaN
0x7ff8000000000000L是long,而不是double,因此不能直接用作字段初始值设定项.
The documentation of Double.NaN确实声明其值“等于Double.longBitsToDouble(0x7ff8000000000000L)返回的值.”但是,优先使用0.0d / 0.0来初始化字段,因为它是编译时常量值,而方法调用则不是.
Why was this value (0x7ff8000000000000L) chosen?
IEEE 754 allows multiple distinct NaN values for each of its single and double floating-point formats. While each hardware architecture returns a particular bit pattern for NaN when a new NaN is generated, a programmer can also create NaNs with different bit patterns to encode, for example, retrospective diagnostic information.
For the most part, the Java SE Platform treats NaN values of a given type as though collapsed into a single canonical value, and hence this specification normally refers to an arbitrary NaN as though to a canonical value.
Double.longBitsToDouble方法必须返回一个值,因此这是他们选择返回的值.