RFR: 8355992: Add unsignedMultiplyExact and *powExact methods to Math and StrictMath [v2]

fabioromano1 duke at openjdk.org
Fri May 2 16:29:46 UTC 2025


On Fri, 2 May 2025 16:23:24 GMT, Raffaello Giulietti <rgiulietti at openjdk.org> wrote:

>> src/java.base/share/classes/java/lang/Math.java line 3567:
>> 
>>> 3565:             return 1;
>>> 3566:         }
>>> 3567:         if (x == 0 || x == 1) {
>> 
>> Suggestion:
>> 
>>         if (x == 0 || x == 1 || n == 1) {
>
> @fabioromano1 Unless there's evidence that these cases are _very very_ common, there's no point in adding fast paths.
> See this comment in `unsignedPowExact(long,int)`
> 
> 
>         /*
>          * To keep the code as simple as possible, there are intentionally
>          * no fast paths, except for |x| <= 1.
>          * The reason is that the number of loop iterations below can be kept
>          * very small when |x| > 1, but not necessarily when |x| <= 1.
>          */

@rgiulietti I would keep at least `n == 1` and `(bitLength(x) - 1L) * n + 1L > SIZE` cases

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/25003#discussion_r2071860872


More information about the core-libs-dev mailing list