When i try to execute this code how result goes greater than Double.MAX_Value?Will overflow/underflow affect double data type in java?
Code:
result = Double.MAX_VALUE * Double.MAX_VALUE;
if (result > Double.MAX_VALUE) {
// Some return statements.
}
From the Java Language Specification
The result of a floating-point multiplication is determined by the rules of IEEE 754 arithmetic:
- [...]
- If the magnitude of the product is too large to represent, we say the operation overflows; the result is then an infinity of appropriate sign.
Since Double.MAX_VALUE * Double.MAX_VALUE is too large to represent, its value becomes 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