Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Double.MIN_VALUE is greater than zero in Java?

Tags:

java

double

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?

like image 428
Krishnamurthy Avatar asked Apr 18 '11 21:04

Krishnamurthy


People also ask

What is the value of double Min_value?

Curiously, Double. MIN_VALUE holds the value 2-1074. This is a positive value, as opposed to Integer. MIN_VALUE which holds the negative value -2147483648.

What is double Min_value in Java?

MIN_VALUE. public static final double MIN_VALUE. A constant holding the smallest positive nonzero value of type double , 2-1074. It is equal to the hexadecimal floating-point literal 0x0. 0000000000001P-1022 and also equal to Double.

Can a double store a negative value in Java?

Floating-Point Data Example On all machines, variables of the float, double, and long double data types can store positive or negative numbers.


1 Answers

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

like image 142
Andy White Avatar answered Sep 21 '22 18:09

Andy White