RFR: 8334755: Asymptotically faster implementation of square root algorithm [v42]

Raffaello Giulietti rgiulietti at openjdk.org
Sat Jul 27 13:48:37 UTC 2024


On Sat, 27 Jul 2024 12:18:19 GMT, fabioromano1 <duke at openjdk.org> wrote:

>> test/micro/org/openjdk/bench/java/math/BigIntegerSquareRoot.java line 74:
>> 
>>> 72: 
>>> 73:         for (int i = 0; i < TESTSIZE; i++) {
>>> 74:             int value = Math.abs(r.nextInt());
>> 
>> There's a risk of an overflow here if the random `int` is `MIN_VALUE`, which would throw an exception later.
>
> The benchmark `BigIntegers.java`, on which I based this, has the same problem.

It wasn't the overflow by itself that worried me, but that a later invocation of `sqrt*()` could throw.

Again, the "huge" numbers are less than 2^66. You might to take a look at `shiftArray` in `BigInteger.java` for inspiration, and adding some leading `0` bits to exercise the normalization/denormalization impact.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/19710#discussion_r1693960748


More information about the core-libs-dev mailing list