The java.lang.Math class doc says,
* In cases where the size is {@code int} or {@code long} and
* overflow errors need to be detected, the methods {@code addExact},
* {@code subtractExact}, {@code multiplyExact}, and {@code toIntExact}
* throw an {@code ArithmeticException} when the results overflow.
* For other arithmetic operations such as divide, absolute value,
* increment by one, decrement by one, and negation, overflow occurs only with
* a specific minimum or maximum value and should be checked against
* the minimum or maximum as appropriate.
There are methods decrementExact(), incrementExact(), and negateExact() that throw exceptions on overflow. These should be included in the list of operations that can detect overflow. The advice about checking specific values still applies to divide and absolute value operations, though.
* In cases where the size is {@code int} or {@code long} and
* overflow errors need to be detected, the methods {@code addExact},
* {@code subtractExact}, {@code multiplyExact}, and {@code toIntExact}
* throw an {@code ArithmeticException} when the results overflow.
* For other arithmetic operations such as divide, absolute value,
* increment by one, decrement by one, and negation, overflow occurs only with
* a specific minimum or maximum value and should be checked against
* the minimum or maximum as appropriate.
There are methods decrementExact(), incrementExact(), and negateExact() that throw exceptions on overflow. These should be included in the list of operations that can detect overflow. The advice about checking specific values still applies to divide and absolute value operations, though.
- csr for
-
JDK-8229473 java.lang.Math class doc should be adjusted regarding -Exact methods
-
- Closed
-
- relates to
-
JDK-8229485 Add decrementExact(), incrementExact(), and negateExact() to java.lang.StrictMath
-
- Resolved
-