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

Add floorDivExact() method to java.lang.[Strict]Math

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 18
    • Fix Version/s: 18
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      b13
    • CPU:
      generic
    • OS:
      generic

      Description

      JDK-8270378 added Math.divideExact() for symmetry with multiplyExact() and to account for the special cases of the division operator '/' where Integer.MIN_VALUE / -1 == Integer.MIN_VALUE and Long.MIN_VALUE / -1 == Long.MIN_VALUE. The same special case also occurs for floorDiv(int,int) as stated in its specification:

      "Returns the largest (closest to positive infinity) int value that is less than or equal to the algebraic quotient. There is one special case, if the dividend is the Integer.MIN_VALUE and the divisor is -1, then integer overflow occurs and the result is equal to the Integer.MIN_VALUE."

      The analogous special case obtains as well for floorDiv(long,long). Instead of ignoring the numeric overflow, a method floorDivExact() would throw an ArithmeticException when the dividend is the respective MIN_VALUE and the divisor is -1.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              bpb Brian Burkhalter
              Reporter:
              bpb Brian Burkhalter
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: