Java 中的 Double.MIN_VALUE 是否大于零?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5709073/
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
Is Double.MIN_VALUE is greater than zero in Java?
提问by Krishnamurthy
I found a bug in my code which boiled down to comparing Double(0.0)
with Double.MIN_VALUE
. Essentially, the following returns false:
我在我的代码中发现了一个错误,归结为Double(0.0)
与Double.MIN_VALUE
. 本质上,以下返回 false:
System.out.println(0.0 > Double.MIN_VALUE);
How is this possible?
这怎么可能?
回答by Andy White
According to the javadoc for Double.MIN_VALUE, MIN_VALUE is:
根据Double.MIN_VALUE的javadoc, MIN_VALUE 是:
A constant holding the smallest positive nonzero value of type double
一个常量,持有 double 类型的最小正非零值
So Double.MIN_VALUE is not negative, it's the positive value that's as close as a Double can get to zero (without being zero).
所以 Double.MIN_VALUE 不是负数,它是正值,它与 Double 可以达到零(不为零)一样接近。
回答by AaronD
Double.MIN_VALUE is the smallest positive non-zero value which can be represented by a Java double (see the JavaDoc at http://download.oracle.com/javase/8/docs/api/java/lang/Double.html).
Double.MIN_VALUE 是可以由 Java 双精度表示的最小正非零值(请参阅http://download.oracle.com/javase/8/docs/api/java/lang/Double.html 上的 JavaDoc ) .