A DESCRIPTION OF THE PROBLEM :
After changing BigInteger.sqrt() algorithm, this can be also used to speed up BigDecimal.sqrt() implementation.
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.
Here is the PR: https://github.com/openjdk/jdk/pull/21301
After changing BigInteger.sqrt() algorithm, this can be also used to speed up BigDecimal.sqrt() implementation.
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.
Here is the PR: https://github.com/openjdk/jdk/pull/21301
- relates to
-
JDK-4851777 Add BigDecimal sqrt method
- Closed
-
JDK-8032027 Add BigInteger square root methods
- Closed
- links to
-
Review(master) openjdk/jdk/21301