RFR: 8341402: BigDecimal's square root optimization [v18]

fabioromano1 duke at openjdk.org
Tue Nov 19 14:14:12 UTC 2024


> 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.

fabioromano1 has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains 22 additional commits since the last revision:

 - Merge branch 'openjdk:master' into patchBigDecimalSqrt
 - Merge branch 'patchBigDecimalSqrt' of https://github.com/fabioromano1/jdk into patchBigDecimalSqrt
 - Optimize sqrt branch for exact results
 - Code simplification
 - Refine documentation
 - Refine documentation
 - Applying suggested changes
 - Avoid overflow
 - adjust to preferred scale in each branch for speed
 - Increment the unscaled sqrt for speed and round the result
 - ... and 12 more: https://git.openjdk.org/jdk/compare/9703530e...ae649247

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/21301/files
  - new: https://git.openjdk.org/jdk/pull/21301/files/2ca5eac9..ae649247

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=21301&range=17
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=21301&range=16-17

  Stats: 403675 lines in 5443 files changed: 191625 ins; 177454 del; 34596 mod
  Patch: https://git.openjdk.org/jdk/pull/21301.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/21301/head:pull/21301

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


More information about the core-libs-dev mailing list