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

add Math.absExact

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Fixed
    • P4
    • 15
    • None
    • core-libs
    • None
    • b18

    Description

      The Math functions abs(int) and abs(long) return MIN_VALUE if MIN_VALUE is provided as input. This is correct and well-defined behavior, but it's counterintuitive, as many people expect the result of abs() always to be positive.

      The Math class includes functions named addExact(), subtractExact(), and multiplyExact() that throw exceptions if boundary cases with integral wraparound are encountered. Perhaps there should be similar functions for abs(), possibly named absExact(), that also throw exceptions for their (single) edge cases. There would need to be overloads for int and long.

      Attachments

        Issue Links

          Activity

            People

              darcy Joe Darcy
              smarks Stuart Marks
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: