On Wed, 4 Dec 2024 14:56:02 GMT, fabioromano1 <d...@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.
>
> fabioromano1 has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   An optimization

Work on this PR also revealed that the previous implementation of 
`stripTrailingZeros()`, while correct, was underperforming on instances with a 
long chain of trailing zeros.
In a side PR, @fabioromano1 improved this with [impressive 
speedups](https://github.com/openjdk/jdk/pull/21323#issuecomment-2403376022) on 
long chains, and without degradations on smaller cases.

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

PR Comment: https://git.openjdk.org/jdk/pull/21301#issuecomment-2659270373

Reply via email to