d java.lang.double_java.lang.Double实现不一致(Oracle JDK 1.8)?

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方法必须返回一个值,因此这是他们选择返回的值.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值