RFR: 8334755: Asymptotically faster implementation of square root algorithm [v28]
Raffaello Giulietti
rgiulietti at openjdk.org
Wed Jul 17 13:59:57 UTC 2024
On Wed, 17 Jul 2024 13:57:06 GMT, fabioromano1 <duke at openjdk.org> wrote:
>> In fact, if you run this code:
>> `long limit = 1L << 32;
>> for (long n = 0; n < limit; n++) {
>> long x = n * n;
>> if (n != (long) Math.sqrt(x >= 0 ? x : x + 0x1p64)) {
>> System.out.println(n);
>> }
>> }`
>>
>> now you find a lot of counterexamples. The question is: why, until recently, if I did run the same code I could not find a counterexample?
>
> I hope these errors are not due to an implementation change in the virtual machine instructions...
There are no counterexamples for perfect squares if you write `long s = (long) Math.rint(Math.sqrt(x >= 0 ? x : x + 0x1p64));`.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/19710#discussion_r1681105600
More information about the core-libs-dev
mailing list