gpt4 book ai didi

java - 从 Double.toLongBits 创建的 long 中获取 double

转载 作者:行者123 更新时间:2023-12-05 09:30:16 26 4
gpt4 key购买 nike

有没有办法将我从 Double.toLongBits 得到的 long 反转为 Double
以下不起作用:

Double n = 171.30672219;
System.out.println(Double.doubleToLongBits(n));
System.out.println(new Double(Double.doubleToLongBits(n)));

这打印:

4640231336019091517
4.6402313360190915E18

虽然我想取回 171.30672219

最佳答案

作为documentation对于 doubleToLongBits 说:

In all cases, the result is a long integer that, when given to the longBitsToDouble(long) method, will produce a floating-point value the same as the argument to doubleToLongBits (except all NaN values are collapsed to a single "canonical" NaN value).

double n = 171.30672219;
System.out.println(Double.doubleToLongBits(n));
System.out.println(Double.longBitsToDouble(Double.doubleToLongBits(n)));

关于java - 从 Double.toLongBits 创建的 long 中获取 double,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69773940/

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