Krishnamurthy
Krishnamurthy

Reputation: 715

Is Double.MIN_VALUE is greater than zero in Java?

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?

Upvotes: 28

Views: 16346

Answers (2)

AaronD
AaronD

Reputation: 1701

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

Upvotes: 6

Andy White
Andy White

Reputation: 88345

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

Upvotes: 46

Related Questions