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

fabioromano1 duke at openjdk.org
Mon Oct 21 17:32:33 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 incrementally with two additional commits since the last revision:

 - Removed unused variable
 - Ensure the result does not exceed the requested precision
   
   Ensure the result does not exceed the requested precision to fit the preferred scale

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/21301/files
  - new: https://git.openjdk.org/jdk/pull/21301/files/2731a724..57034fed

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

  Stats: 13 lines in 1 file changed: 5 ins; 2 del; 6 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