RFR: 8356891: Some code simplifications for basic BigIntegers' bit operations
Chen Liang
liach at openjdk.org
Tue May 13 18:02:05 UTC 2025
On Mon, 12 May 2025 01:46:25 GMT, David Schlosnagle <duke at openjdk.org> wrote:
>> Some changes in `Biginteger`s' bit operations that increase the code readability and slightly optimize the execution time.
>
> src/java.base/share/classes/java/math/BigInteger.java line 2642:
>
>> 2640: }
>> 2641: // (this.abs().bitLength() - 1L) * exponent + 1L > Integer.MAX_VALUE
>> 2642: if (scaleFactor + bitsToShift - exponent >= Integer.MAX_VALUE) {
>
> If this is overflow sensitive code, should this avoid adding on the left hand side?
>
> Suggestion:
>
> if (scaleFactor - exponent >= Integer.MAX_VALUE - bitsToShift) {
I think we are fine here, `scaleFactor` is already `long`
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25166#discussion_r2083704486
More information about the core-libs-dev
mailing list