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

Raffaello Giulietti rgiulietti at openjdk.org
Fri May 2 16:56:46 UTC 2025


On Fri, 2 May 2025 16:26:48 GMT, fabioromano1 <duke at openjdk.org> wrote:

>> @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

Again, I don't think that `n == 1` is a frequent case which would make any practical difference.

As for the `bitLength` check, the product might overflow.
Further, `bitLength` might not be that cheap.
Finally, the test would just help to _fail_ faster at the expense of making the successful runs slightly slower.

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

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


More information about the core-libs-dev mailing list