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

Add unsignedMultiplyExact and *powExact methods to Math and StrictMath

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • None
    • core-libs
    • In Review

      Math (and StrictMath) offer signed `multiplyExact` methods that throw on overflow. However, there are no corresponding `unsignedMultiplyExact` methods. Since the conditions for overflow are different, the signed version cannot be just used as replacements.

      Further, there are no `powExact()` and `unsignedPowExact()` methods that operate on integer valued arguments. Similar methods are often implemented in ad-hoc ways, without checking for overflows. Thus, they silently return incorrect values, leading to the usual issues associated with overflowing arithmetic. The proposed methods provide a safe alternative.

            rgiulietti Raffaello Giulietti
            rgiulietti Raffaello Giulietti
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: