gpt4 book ai didi

java - 其他 NaN 值是什么?

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:09:13 25 4
gpt4 key购买 nike

documentation for java.lang.Double.NaN说是

A constant holding a Not-a-Number (NaN) value of type double. It is equivalent to the value returned by Double.longBitsToDouble(0x7ff8000000000000L).

这似乎暗示还有其他的。如果是这样,我如何获得它们,这是否可以便携地完成?

明确地说,我想找到 doublex 使得

Double.doubleToRawLongBits(x) != Double.doubleToRawLongBits(Double.NaN)

Double.isNaN(x)

都是真的。

最佳答案

您需要 doubleToRawLongBits 而不是 doubleToLongBits

doubleToRawLongBits 提取实际的二进制表示。 doubleToLongBits 没有,它首先将所有 NaN 转换为默认的 NaN

double n = Double.longBitsToDouble(0x7ff8000000000000L); // default NaN
double n2 = Double.longBitsToDouble(0x7ff8000000000100L); // also a NaN, but M != 0

System.out.printf("%X\n", Double.doubleToLongBits(n));
System.out.printf("%X\n", Double.doubleToRawLongBits(n));
System.out.printf("%X\n", Double.doubleToLongBits(n2));
System.out.printf("%X\n", Double.doubleToRawLongBits(n2));

输出:

7FF8000000000000
7FF8000000000000
7FF8000000000000
7FF8000000000100

关于java - 其他 NaN 值是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2154484/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com