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

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

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 18
    • 18
    • core-libs
    • None
    • b13
    • generic
    • generic

      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.

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

              Created:
              Updated:
              Resolved: