user492888
user492888

Reputation: 207

why java is returning positive infinity when it exceed Double.Max_Value?

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

Answers (1)

Sotirios Delimanolis
Sotirios Delimanolis

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

Related Questions