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?
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.
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.
Floating-Point Data Example On all machines, variables of the float, double, and long double data types can store positive or negative numbers.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With