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

Raffaello Giulietti rgiulietti at openjdk.org
Fri Jul 12 15:15:53 UTC 2024


On Fri, 12 Jul 2024 14:22:33 GMT, fabioromano1 <duke at openjdk.org> wrote:

>> src/java.base/share/classes/java/math/MutableBigInteger.java line 2054:
>> 
>>> 2052: 
>>> 2053:                 rem.add(ONE);
>>> 2054:                 rem.subtract(twiceSqrt);
>> 
>> Shouldn't these be `rem + twiceSqrt - 1`?
>
> No, because `rem` is unsigned, so to perform the correct computation you must first add the absolute value of the addends with the same sign, and then subtract the absolute value of those with opposite sign.

Ah right, this is the semantics of `MBI.subtract`.

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

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


More information about the core-libs-dev mailing list