On Tue, 19 Nov 2024 18:44:27 GMT, Raffaello Giulietti <rgiulie...@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

Reply via email to