RFR: 8075806: divideExact is missing in java.lang.Math

Raffaello Giulietti raffaello.giulietti at gmail.com
Wed Jul 14 19:26:35 UTC 2021


One could also divide first and then check the result:

int q = x / y;
if ((x & y & q) >= 0) {
     return r;
}
throw new ArithmeticException("integer overflow");

No idea about relative perf.



On 2021-07-13 19:32, Brian Burkhalter wrote:
> Please consider this proposal to add `divideExact()` methods for integral data types to `java.lang.Math` thereby rounding out "exact" support to all four basic arithmetic operations.
> 
> -------------
> 
> Commit messages:
>   - 8075806: divideExact is missing in java.lang.Math
> 
> Changes: https://git.openjdk.java.net/jdk/pull/4770/files
>   Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=4770&range=00
>    Issue: https://bugs.openjdk.java.net/browse/JDK-8075806
>    Stats: 109 lines in 2 files changed: 100 ins; 5 del; 4 mod
>    Patch: https://git.openjdk.java.net/jdk/pull/4770.diff
>    Fetch: git fetch https://git.openjdk.java.net/jdk pull/4770/head:pull/4770
> 
> PR: https://git.openjdk.java.net/jdk/pull/4770
> 


More information about the core-libs-dev mailing list