Is Double.MIN_VALUE is greater than zero in Java?

≯℡__Kan透↙ 提交于 2019-12-30 05:45:26

问题


I found a bug in my code which boiled down to comparing Double(0.0) with Double.MIN_VALUE. Essentially, the following returns false:

System.out.println(0.0 > Double.MIN_VALUE);

How is this possible?


回答1:


According to the javadoc for Double.MIN_VALUE, MIN_VALUE is:

A constant holding the smallest positive nonzero value of type 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).




回答2:


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).



来源:https://stackoverflow.com/questions/5709073/is-double-min-value-is-greater-than-zero-in-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!