4

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.

4
  • 2
    It's a special case Commented Jul 27, 2018 at 5:02
  • 1
    When you say "gives", are you meaning the string representation? The way a double is converted to a string is described in detail in the Javadoc. Commented Jul 27, 2018 at 5:03
  • Maybe you can find the desired answer here: JLS §4.2.3. Commented Jul 27, 2018 at 5:10
  • 1
    double includes numbers, and it includes infinity, and it includes NaN. Commented Jul 27, 2018 at 5:35

2 Answers 2

7

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much. That explains everything :)
1

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 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.