RFR: 8355719: Reduce memory consumption of BigInteger.pow() [v51]
Raffaello Giulietti
rgiulietti at openjdk.org
Wed May 7 17:46:19 UTC 2025
On Wed, 7 May 2025 17:34:27 GMT, fabioromano1 <duke at openjdk.org> wrote:
>> Ah right, but you probably want
>> Suggestion:
>>
>> if ((bitLength() - 1L) * exponent > Integer.MAX_VALUE) {
>>
>> I mean `>` rather than `>=`
>
>> Ah right, but you probably want
>
> No, the sufficient condition to get the overflow is `(bitLength() - 1L) * exponent + 1L > Integer.MAX_VALUE`, which is equivalent to that one I wrote above.
At some point you proposed
(bitLength() - 1L) * exponent >= (long) MAX_MAG_LENGTH << 5
Given the value of `MAX_MAG_LENGTH`, which is 2^26, this is equivalent to
(bitLength() - 1L) * exponent >= 1L << 31
that is, to
(bitLength() - 1L) * exponent > Integer.MAX_VALUE
What am I missing?
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/24690#discussion_r2078163320
More information about the core-libs-dev
mailing list