On Mon, 25 Nov 2024 19:36:04 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: > > Added tests for exact results path Thanks. What about the coverage of the other paths in the `sqrt()` code? test/jdk/java/math/BigDecimal/SquareRootTests.java line 200: > 198: // mc.roundingMode != RoundingMode.UNNECESSARY && > mc.precision == 0 > 199: try { > 200: result = BigDecimal.TEN.sqrt(arbitrary); Suggestion: result = input.sqrt(arbitrary); ------------- PR Review: https://git.openjdk.org/jdk/pull/21301#pullrequestreview-2461649513 PR Review Comment: https://git.openjdk.org/jdk/pull/21301#discussion_r1858609104