RFR: 8334755: Asymptotically faster implementation of square root algorithm [v23]
Raffaello Giulietti
rgiulietti at openjdk.org
Fri Jul 12 14:44:53 UTC 2024
On Fri, 12 Jul 2024 13:57:55 GMT, fabioromano1 <duke at openjdk.org> wrote:
>> (Yes, I proved it to myself in this way.)
>>
>> A similar explanation should be in a comment in the code, not here. The source of truth is the code, not the comments on GitHub ;-)
>
> I would keep zero as the only special case, so as not to have to modify `x > 0` with `x >= 0` in `Math.sqrt(x > 0 ? x : x + 0x1p64)`.
I can't see any real-world performance benefit in having a special case for `0` since, functionally, the code for the generic (unsigned) `long` works correctly. Except if there's evidence that a `0` argument is used in a vast majority of cases, which I doubt.
The aim is to simplify as much as reasonably possible without incurring real performance issues.
Changing `>` to `>=` makes the code correct even when nothing is assumed about the range of `x`.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/19710#discussion_r1676035453
More information about the core-libs-dev
mailing list