RFR: 8334755: Asymptotically faster implementation of square root algorithm [v30]
Raffaello Giulietti
rgiulietti at openjdk.org
Thu Jul 18 15:25:40 UTC 2024
On Thu, 18 Jul 2024 15:09:41 GMT, fabioromano1 <duke at openjdk.org> wrote:
>>> I mean only restricted to unsigned `long` perfect squares, something like the following, but written as a proper test
>>>
>>> ```
>>> long i = 0;
>>> for (; i < 1L << 32; ++i) {
>>> long x = i * i;
>>> long s = (long) Math.sqrt(x >= 0 ? x : x + 0x1p64);
>>> if (!(s + 1 == i || s == i)) {
>>> System.out.format("oops... i=%d, but s=%d%n", i, s);
>>> System.exit(1);
>>> }
>>> }
>>> ```
>>
>> So, it is okay although the code does not test directly BigInteger.sqrt()?
>
> I found the way: I can test directly the code through `java.math.Accessor.java`
I think there's a misunderstanding here.
What I'd like to see is a test that verifies the claim
/* For every long value s in [0, 2^32) such that x == s * s,
* it is true that s - 1 <= (long) Math.sqrt(x >= 0 ? x : x + 0x1p64) <= s,
A test similar to my code above should be more than enough.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/19710#discussion_r1683045737
More information about the core-libs-dev
mailing list