RFR: 8366478: BigDecimal roots [v4]

Raffaello Giulietti rgiulietti at openjdk.org
Fri Oct 17 16:26:58 UTC 2025


On Fri, 17 Oct 2025 16:21:03 GMT, Joe Darcy <darcy at openjdk.org> wrote:

>>> Yes, but this is inconsistent with the definition of _preferred scale_ for `BigDecimal.sqrt()`.
>> 
>> Looks like I included a bug with BigDecimals.sqrt with respect to scaling then. While I noted a correct translation of the IEEE 754 requirement in 
>> 
>> https://bugs.openjdk.org/browse/JDK-4851777?focusedId=13847551&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-13847551
>> 
>> that did not get carried over to the BigDecimal.sqrt spec or implementation.
>> 
>> I've filed https://bugs.openjdk.org/browse/JDK-8370057; thanks.
>
>> I leave that decision to @jddarcy. But for consistency with IEEE 754, we should use `ceilDiv(this.scale(), n)` even for `n = 2`.
>> 
>> @fabioromano1 I guess that implementation-wise it would be an easy change?
>> 
>> Also, should we perhaps rename the method to `rootn()`, as in IEEE 754? We still have time before RDP 1.
> 
> The BigDecimal.sqrt scale bug should be resolved in its own issue; it will require a CSR for compatibility analysis.
> 
> The IEEE 754 terminology is guidance, but not one we strictly have to follow if we have cause not to.

OK, so let's go with the truncated division for now, since `sqrt()` delegates to `ntRoot()`.
As for the name, shall we replace it with `rootn()`?

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/27148#discussion_r2440536555


More information about the core-libs-dev mailing list