This may be a very simple question but I am very confused here.
Double.MAX_VALUE
gives 1.7976931348623157E308
which indeed is a floating point literal and hence double
.
However, Double.POSITIVE_INFINITY
gives infinity. How is infinity of type Double
? It doesn't look like a decimal number or even a number.
Please explain.
At a binary level in IEEE 754 (which is not exactly the same as Java floating point), infinity is represented as:
Positive and negative infinity are represented thus:
sign = 0 for positive infinity, 1 for negative infinity.
biased exponent = all 1 bits.
fraction = all 0 bits.
POSITIVE_INFINITY
(and its counterpart, NEGATIVE_INFINITY
) are special constants that Java uses to notify you of overflow of certain operations where the result can no longer be represented as a Double (or Float) value, e.g.
System.out.println( 1E300 * 1E20 ); // Infinity
System.out.println( –1E300 * 1E20 ); // -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