java 获得最负双的正确方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2389613/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Correct Way to Obtain The Most Negative Double
提问by Cheok Yan Cheng
Is this the correct way to obtain the most negative double in Java?
这是在 Java 中获得最负双倍的正确方法吗?
double v = -Double.MAX_VALUE;
采纳答案by RHSeeger
Assuming you mean the largest negative, non-infinite number, sounds correct because, for floating point numbers in 64-bit IEEE 754 floating point(which is what Java uses for doubles):
假设您的意思是最大的负数,非无限数,听起来是正确的,因为对于64 位 IEEE 754 浮点数中的浮点数(这是Java 用于 doubles 的):
- The size of the number is stored in one part of the binary rep
- The sign of the number is stored in a separate part of the binary rep
- 数字的大小存储在二进制表示的一部分中
- 数字的符号存储在二进制表示的单独部分
Therefore:The largest representable negative number would be the same as the largest representable positive number with the sign bit flipped to indicate a negative number.
因此:最大可表示负数将与最大可表示正数相同,符号位翻转以指示负数。
回答by Sean Owen
Nope, it's Double.NEGATIVE_INFINITY.
不,它是 Double.NEGATIVE_INFINITY。

