Reputation: 207
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.
}
Upvotes: 3
Views: 934
Reputation: 279900
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.
Upvotes: 6