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.
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.
- csr for
-
JDK-8356077 Add unsignedMultiplyExact and *powExact methods to Math and StrictMath
-
- Finalized
-
- links to
-
Review(master) openjdk/jdk/25003