Java: Why's Double.MIN_VALUE is positive? Integer.MIN_VALUE is negative!

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.

The reason is most likely that the smallest double value is easily expressed as -Double.MAX_VALUE. The IEEE 754 format has one bit reserved for the sign and the remaining bits representing the magnitude. This means that it is symmetrical around origo (as opposed int values, which have one more negative value).

So what's up with 2-1074?

This value is the smallest value greater than 0 that the IEEE 754 allows you to express. So Double.MIN_VALUE (and Double.MAX_VALUE) should be thought of as the minimum (and maximum) positive magnitudes.

Finally, the same constant is called Double.EPSILON in .NET, which is arguably a better name.

Comments

Be the first to comment!