public class Test {
public static void main(String[] args) {
boolean v1 = -25 <= Double.MIN_VALUE;
boolean v2 = -25 <= -100.0;
System.out.println(v1); //true
System.out.println(v2); //false
}
}
Here -25 <= Double.MIN_VALUE should result in false, but it shows true! Again, when comparing -25 <= -100.0, it outputs the correct value.
What am I missing here? I think this might be due to comparing int and double, but still this doesn’t make sense, since the second test is also a similar one but returns correct value.
Edit: I should’ve checked against Double.NEGATIVE_INIFINITY, since this is the one that returns a negative value. Double.MIN_VALUE returns the smallest positive value, not the smallest negative value. This is not to confuse with Integer.MIN_VALUE, which really is in fact the smallest negative integer.
>Solution :
**
* A constant holding the smallest positive nonzero value of type
* {@code double}, 2<sup>-1074</sup>. It is equal to the
* hexadecimal floating-point literal
* {@code 0x0.0000000000001P-1022} and also equal to
* {@code Double.longBitsToDouble(0x1L)}.
*/
public static final double MIN_VALUE = 0x0.0000000000001P-1022; // 4.9e-324
Check in your JDK what double.MIN_VALUE represents.
It says the smallest positive value!
Your negative value -25 will always be smaller than any positive number.