Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8229337

java.lang.Math class doc should be adjusted regarding -Exact methods

    XMLWordPrintable

Details

    • b12

    Description

      The java.lang.Math class doc says,

       * In cases where the size is {@code int} or {@code long} and
       * overflow errors need to be detected, the methods {@code addExact},
       * {@code subtractExact}, {@code multiplyExact}, and {@code toIntExact}
       * throw an {@code ArithmeticException} when the results overflow.
       * For other arithmetic operations such as divide, absolute value,
       * increment by one, decrement by one, and negation, overflow occurs only with
       * a specific minimum or maximum value and should be checked against
       * the minimum or maximum as appropriate.

      There are methods decrementExact(), incrementExact(), and negateExact() that throw exceptions on overflow. These should be included in the list of operations that can detect overflow. The advice about checking specific values still applies to divide and absolute value operations, though.

      Attachments

        Issue Links

          Activity

            People

              jboes Julia Boes (Inactive)
              smarks Stuart Marks
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: