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

Raffaello Giulietti rgiulietti at openjdk.org
Wed Jul 17 15:10:55 UTC 2024


On Wed, 17 Jul 2024 14:30:33 GMT, fabioromano1 <duke at openjdk.org> wrote:

>> I tried on older release, they all agree.
>
> @rgiulietti  This is so strange... anyway, I tried also `long x = n * n`, `long s = Math.round(Math.sqrt(x >= 0 ? x : x + 0x1p64))` with the test `s < n`, which I think it's more mathematically natural, and also this never fails for perfect squares.

Also, this avoids a test

            if (Long.compareUnsigned(x, s * s - 1) <= 0) {  // benign over- and underflows
                s--;
            }

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

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


More information about the core-libs-dev mailing list