Why this code does't work? Actually,this is just the small part of a big program. It has to compare Double.MIN_VALUE to different values, it works with all values except 0. ,why? Thanks!
double d = Double.MIN_VALUE;
if (0. > d) {
System.out.println("OK");
}
The Double.MIN_VALUE is 4.9E-324. And this is not less than 0. But it is not actually 0.
If you print
System.out.println(4.9E-324d > 0.);//this is true
In this sense,
0.0000000000...0001 != 0. But it tends to 0
The same way 4.9E-324d != 0 but tends to 0
Double.MIN_VALUE is actually a bad name for the constant in Java. It does not fit to int.MIN_VALUE. In C# it is called Double.Epsilon, which IMHO fits better.
So, Double.MIN_VALUE is not the largest negative double value that exists. IMHO there's no such constant for the largest discrete Double number. Otherwise, the largest negative number is Double.NEGATIVE_INFINITY.
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