Is Double.MIN_VALUE is greater than zero in Java?

2020-03-01 03:22发布

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?

标签: java double
2条回答
女痞
2楼-- · 2020-03-01 03:50

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

查看更多
▲ chillily
3楼-- · 2020-03-01 04:07

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

查看更多
登录 后发表回答