RFR: 8341402: BigDecimal's square root optimization [v20]
fabioromano1
duke at openjdk.org
Tue Nov 19 19:06:03 UTC 2024
On Tue, 19 Nov 2024 18:44:27 GMT, Raffaello Giulietti <rgiulietti at openjdk.org> wrote:
>> fabioromano1 has updated the pull request incrementally with one additional commit since the last revision:
>>
>> Correct remainder checking
>
> 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`.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/21301#discussion_r1848892890
More information about the core-libs-dev
mailing list