RFR: 8341402: BigDecimal's square root optimization [v20]
Raffaello Giulietti
rgiulietti at openjdk.org
Tue Nov 19 19:51:52 UTC 2024
On Tue, 19 Nov 2024 19:02:09 GMT, fabioromano1 <duke at openjdk.org> wrote:
>> src/java.base/share/classes/java/math/BigDecimal.java line 2253:
>>
>>> 2251:
>>> 2252: case UP, CEILING -> {
>>> 2253: BigInteger[] sqrtRem = workingInt.sqrtAndRemainder();
>>
>> Can't this follow the same logic as for the halfway cases, with just `sqrt()` and a `!workingInt.equals(sqrt.multiply(sqrt))` test? This would increase consistency.
>> Are there performance reasons to do it as in the current code?
>
> Yes, indeed in this case the remainder is always needed, so invoking `workingInt.sqrtAndRemainder()` is faster than checking `!workingInt.equals(sqrt.multiply(sqrt))`, as it avoids the squaring of `sqrt`.
I see.
I have no other comments on the code. I look forward for the tests.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/21301#discussion_r1848971914
More information about the core-libs-dev
mailing list