Integrated: 8341402: BigDecimal's square root optimization

fabioromano1 duke at openjdk.org
Thu Apr 10 14:37:39 UTC 2025


On Wed, 2 Oct 2024 10:31:09 GMT, fabioromano1 <duke at openjdk.org> wrote:

> After changing `BigInteger.sqrt()` algorithm, this can be also used to speed up `BigDecimal.sqrt()` implementation. Here is how I made it.
> 
> The main steps of the algorithm are as follows:
> first argument reduce the value to an integer using the following relations:
> 
> x = y * 10 ^ exp
> sqrt(x) = sqrt(y) * 10^(exp / 2) if exp is even
> sqrt(x) = sqrt(y*10) * 10^((exp-1)/2) is exp is odd
> 
> Then use BigInteger.sqrt() on the reduced value to compute the numerical digits of the desired result.
> 
> Finally, scale back to the desired exponent range and perform any adjustment to get the preferred scale in the representation.

This pull request has now been integrated.

Changeset: c4c3edfa
Author:    fabioromano1 <51378941+fabioromano1 at users.noreply.github.com>
Committer: Raffaello Giulietti <rgiulietti at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/c4c3edfa964ef504f12971c5deef7c7355bdf325
Stats:     453 lines in 2 files changed: 226 ins; 187 del; 40 mod

8341402: BigDecimal's square root optimization

Reviewed-by: rgiulietti

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

PR: https://git.openjdk.org/jdk/pull/21301


More information about the core-libs-dev mailing list