Re: RFR: 8075806: divideExact is missing in java.lang.Math [v6]
> 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. Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision: 8075806: Add divideExact() to list of tested methods - Changes: - all: https://git.openjdk.java.net/jdk/pull/4770/files - new: https://git.openjdk.java.net/jdk/pull/4770/files/5093a2e8..1dabf117 Webrevs: - full: https://webrevs.openjdk.java.net/?repo=jdk=4770=05 - incr: https://webrevs.openjdk.java.net/?repo=jdk=4770=04-05 Stats: 6 lines in 1 file changed: 2 ins; 0 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
Re: RFR: 8075806: divideExact is missing in java.lang.Math [v5]
On Thu, 22 Jul 2021 19:40:46 GMT, 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. > > Brian Burkhalter has updated the pull request incrementally with one > additional commit since the last revision: > > 8075806: Clean up division by zero verbiage Marked as reviewed by darcy (Reviewer). test/jdk/java/lang/Math/ExactArithTests.java line 135: > 133: } > 134: > 135: boolean exceptionExpected = false; Please add "divideExact" to the list of methods tested by static void testIntegerExact(int x, int y) and similar change for long. - PR: https://git.openjdk.java.net/jdk/pull/4770
Re: RFR: 8075806: divideExact is missing in java.lang.Math [v5]
> 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. Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision: 8075806: Clean up division by zero verbiage - Changes: - all: https://git.openjdk.java.net/jdk/pull/4770/files - new: https://git.openjdk.java.net/jdk/pull/4770/files/328e4188..5093a2e8 Webrevs: - full: https://webrevs.openjdk.java.net/?repo=jdk=4770=04 - incr: https://webrevs.openjdk.java.net/?repo=jdk=4770=03-04 Stats: 16 lines in 2 files changed: 4 ins; 0 del; 12 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
Re: RFR: 8075806: divideExact is missing in java.lang.Math [v4]
> 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. Brian Burkhalter has refreshed the contents of this pull request, and previous commits have been removed. The incremental views will show differences compared to the previous content of the PR. The pull request contains one new commit since the last revision: 8075806: Add StrictMath analogs - Changes: - all: https://git.openjdk.java.net/jdk/pull/4770/files - new: https://git.openjdk.java.net/jdk/pull/4770/files/60adb9e5..328e4188 Webrevs: - full: https://webrevs.openjdk.java.net/?repo=jdk=4770=03 - incr: https://webrevs.openjdk.java.net/?repo=jdk=4770=02-03 Stats: 7 lines in 1 file changed: 0 ins; 5 del; 2 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
Re: RFR: 8075806: divideExact is missing in java.lang.Math [v3]
> 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. Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision: 8075806: Add StrictMath analogs - Changes: - all: https://git.openjdk.java.net/jdk/pull/4770/files - new: https://git.openjdk.java.net/jdk/pull/4770/files/6843e666..60adb9e5 Webrevs: - full: https://webrevs.openjdk.java.net/?repo=jdk=4770=02 - incr: https://webrevs.openjdk.java.net/?repo=jdk=4770=01-02 Stats: 46 lines in 1 file changed: 46 ins; 0 del; 0 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
Re: RFR: 8075806: divideExact is missing in java.lang.Math
On Wed, 14 Jul 2021 16:45:20 GMT, Joe Darcy wrote: > Are there examples in the JDK or its tests where a method with this > definition would be used? I have not identified any as yet. I did verify however that there are no uses in `open/src/**/*.java` of either `absExact()` or `negateExact()`, only their implementations in `[Strict]Math`. - PR: https://git.openjdk.java.net/jdk/pull/4770
Re: RFR: 8075806: divideExact is missing in java.lang.Math [v2]
On Wed, 14 Jul 2021 16:43:32 GMT, Joe Darcy wrote: >> Brian Burkhalter has updated the pull request incrementally with one >> additional commit since the last revision: >> >> 8075806: Separate div-by-0 verbiage; change impl > > src/java.base/share/classes/java/lang/Math.java line 1008: > >> 1006: * Returns the quotient of the arguments, throwing an exception if >> the >> 1007: * result overflows an {@code int}. Such overflow can occur if >> and only >> 1008: * if either {@code y} is zero, or both {@code x} is > > I think the divide by zero case should be discussed separately from overflow. Fixed. - PR: https://git.openjdk.java.net/jdk/pull/4770
Re: RFR: 8075806: divideExact is missing in java.lang.Math [v2]
> 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. Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision: 8075806: Separate div-by-0 verbiage; change impl - Changes: - all: https://git.openjdk.java.net/jdk/pull/4770/files - new: https://git.openjdk.java.net/jdk/pull/4770/files/db216a6d..6843e666 Webrevs: - full: https://webrevs.openjdk.java.net/?repo=jdk=4770=01 - incr: https://webrevs.openjdk.java.net/?repo=jdk=4770=00-01 Stats: 29 lines in 1 file changed: 8 ins; 3 del; 18 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
Re: RFR: 8075806: divideExact is missing in java.lang.Math
Mysteries of JIT compilation... On 2021-07-14 21:53, Brian Burkhalter wrote: On Tue, 13 Jul 2021 17:21:52 GMT, 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. @rgiulietti Actually your trick is the fastest: `yours > via negateExact() > original`. Thanks! - PR: https://git.openjdk.java.net/jdk/pull/4770
Re: RFR: 8075806: divideExact is missing in java.lang.Math
On Tue, 13 Jul 2021 17:21:52 GMT, 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. @rgiulietti Actually your trick is the fastest: `yours > via negateExact() > original`. Thanks! - PR: https://git.openjdk.java.net/jdk/pull/4770
Re: RFR: 8075806: divideExact is missing in java.lang.Math
On Tue, 13 Jul 2021 17:21:52 GMT, 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. Thanks. I was thinking of leveraging the `negateExact()` intrinsic instead: // Leverage a potential intrinsic of negateExact() return y == -1 ? Math.negateExact(x) : x/y; - PR: https://git.openjdk.java.net/jdk/pull/4770
Re: RFR: 8075806: divideExact is missing in java.lang.Math
Sorry, typo int q = x / y; if ((x & y & q) >= 0) { return q; // q, not r } throw new ArithmeticException("integer overflow"); On 2021-07-14 21:26, Raffaello Giulietti wrote: 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=4770=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
Re: RFR: 8075806: divideExact is missing in java.lang.Math
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=4770=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
Re: RFR: 8075806: divideExact is missing in java.lang.Math
On Tue, 13 Jul 2021 17:21:52 GMT, 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. Are there examples in the JDK or its tests where a method with this definition would be used? src/java.base/share/classes/java/lang/Math.java line 1008: > 1006: * Returns the quotient of the arguments, throwing an exception if > the > 1007: * result overflows an {@code int}. Such overflow can occur if and > only > 1008: * if either {@code y} is zero, or both {@code x} is I think the divide by zero case should be discussed separately from overflow. - PR: https://git.openjdk.java.net/jdk/pull/4770
Re: RFR: 8075806: divideExact is missing in java.lang.Math
On Tue, 13 Jul 2021 17:21:52 GMT, 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. Note: The `StrictMath` equivalents were intentionally omitted until the review converges to a consensus. - PR: https://git.openjdk.java.net/jdk/pull/4770