Re: RFR: 8341402: BigDecimal's square root optimization [v31]

2025-04-10 Thread Joe Darcy
On Tue, 18 Mar 2025 14:46:01 GMT, fabioromano1 wrote: >> fabioromano1 has updated the pull request incrementally with one additional >> commit since the last revision: >> >> An optimization > > This comment is to avoid closing this PR. > @fabioromano1 Thanks so much for your great work and p

Re: RFR: 8341402: BigDecimal's square root optimization [v32]

2025-04-10 Thread duke
On Fri, 28 Mar 2025 18:24:49 GMT, fabioromano1 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 i

Re: RFR: 8341402: BigDecimal's square root optimization [v32]

2025-04-10 Thread Raffaello Giulietti
On Fri, 28 Mar 2025 18:24:49 GMT, fabioromano1 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 i

Re: RFR: 8341402: BigDecimal's square root optimization [v31]

2025-04-04 Thread fabioromano1
On Wed, 4 Dec 2024 14:56:02 GMT, fabioromano1 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 in

Re: RFR: 8341402: BigDecimal's square root optimization [v32]

2025-03-28 Thread fabioromano1
> 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 >

Re: RFR: 8341402: BigDecimal's square root optimization [v31]

2025-02-14 Thread Raffaello Giulietti
On Wed, 4 Dec 2024 14:56:02 GMT, fabioromano1 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 in

Re: RFR: 8341402: BigDecimal's square root optimization [v31]

2025-02-13 Thread Joe Darcy
On Mon, 10 Feb 2025 09:17:51 GMT, Per Minborg wrote: > This PR seems to be targeting performance, yet no benchmarks are provided > comparing the current vs. proposed branch with respect to performance. We > need to understand the upside of the proposed changes. At my request, reimplementing Bi

Re: RFR: 8341402: BigDecimal's square root optimization [v31]

2025-02-10 Thread fabioromano1
On Mon, 10 Feb 2025 09:17:51 GMT, Per Minborg wrote: >> fabioromano1 has updated the pull request incrementally with one additional >> commit since the last revision: >> >> An optimization > > This PR seems to be targeting performance, yet no benchmarks are provided > comparing the current v

Re: RFR: 8341402: BigDecimal's square root optimization [v31]

2025-02-10 Thread Per Minborg
On Wed, 4 Dec 2024 14:56:02 GMT, fabioromano1 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 in

Re: RFR: 8341402: BigDecimal's square root optimization [v31]

2025-02-08 Thread fabioromano1
On Wed, 4 Dec 2024 14:56:02 GMT, fabioromano1 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 in

Re: RFR: 8341402: BigDecimal's square root optimization [v31]

2025-01-11 Thread fabioromano1
On Wed, 4 Dec 2024 14:56:02 GMT, fabioromano1 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 in

Re: RFR: 8341402: BigDecimal's square root optimization [v31]

2024-12-13 Thread Joe Darcy
On Wed, 4 Dec 2024 14:56:02 GMT, fabioromano1 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 in

Re: RFR: 8341402: BigDecimal's square root optimization [v31]

2024-12-04 Thread fabioromano1
> 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 >

Re: RFR: 8341402: BigDecimal's square root optimization [v30]

2024-11-29 Thread fabioromano1
> 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 >

Re: RFR: 8341402: BigDecimal's square root optimization [v29]

2024-11-29 Thread fabioromano1
> 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 >

Re: RFR: 8341402: BigDecimal's square root optimization [v28]

2024-11-28 Thread fabioromano1
> 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 >

Re: RFR: 8341402: BigDecimal's square root optimization [v26]

2024-11-28 Thread fabioromano1
> 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 >

Re: RFR: 8341402: BigDecimal's square root optimization [v27]

2024-11-28 Thread fabioromano1
> 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 >

Re: RFR: 8341402: BigDecimal's square root optimization [v25]

2024-11-28 Thread fabioromano1
> 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 >

Re: RFR: 8341402: BigDecimal's square root optimization [v23]

2024-11-28 Thread Raffaello Giulietti
On Tue, 26 Nov 2024 17:27:58 GMT, fabioromano1 wrote: >> I don't get your point. Here's an example: >> >> BigDecimal.ONE.sqrt(new MathContext(2_000_000_000, RoundingMode.UP)) >> | Exception java.lang.ArithmeticException: Overflow >> |at BigDecimal.sqrt (BigDecimal.java:2226) >> |

Re: RFR: 8341402: BigDecimal's square root optimization [v24]

2024-11-26 Thread fabioromano1
> 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 >

Re: RFR: 8341402: BigDecimal's square root optimization [v23]

2024-11-26 Thread Raffaello Giulietti
On Tue, 26 Nov 2024 17:31:38 GMT, Raffaello Giulietti wrote: >>> I don't get your point. Here's an example: >>> >>> ``` >>> BigDecimal.ONE.sqrt(new MathContext(2_000_000_000, RoundingMode.UP)) >>> | Exception java.lang.ArithmeticException: Overflow >>> |at BigDecimal.sqrt (BigDecimal.j

Re: RFR: 8341402: BigDecimal's square root optimization [v23]

2024-11-26 Thread Raffaello Giulietti
On Tue, 26 Nov 2024 17:27:58 GMT, fabioromano1 wrote: >> I don't get your point. Here's an example: >> >> BigDecimal.ONE.sqrt(new MathContext(2_000_000_000, RoundingMode.UP)) >> | Exception java.lang.ArithmeticException: Overflow >> |at BigDecimal.sqrt (BigDecimal.java:2226) >> |

Re: RFR: 8341402: BigDecimal's square root optimization [v23]

2024-11-26 Thread fabioromano1
On Tue, 26 Nov 2024 17:22:41 GMT, Raffaello Giulietti wrote: > I don't get your point. Here's an example: > > ``` > BigDecimal.ONE.sqrt(new MathContext(2_000_000_000, RoundingMode.UP)) > | Exception java.lang.ArithmeticException: Overflow > |at BigDecimal.sqrt (BigDecimal.java:2226) >

Re: RFR: 8341402: BigDecimal's square root optimization [v23]

2024-11-26 Thread Raffaello Giulietti
On Tue, 26 Nov 2024 17:13:04 GMT, fabioromano1 wrote: >>> OK. But for the sake of completeness, I would add at least one test case >>> for an overflowing `workingScale`. >> >> I'm afraid it's not possible to produce such a test case, with the current >> implementation of `BigInteger`. >> Indee

Re: RFR: 8341402: BigDecimal's square root optimization [v23]

2024-11-26 Thread fabioromano1
On Tue, 26 Nov 2024 17:04:49 GMT, fabioromano1 wrote: >> OK. >> But for the sake of completeness, I would add at least one test case for an >> overflowing `workingScale`. >> >> Other than that, the PR is then in good shape for approval. > >> OK. But for the sake of completeness, I would add at

Re: RFR: 8341402: BigDecimal's square root optimization [v23]

2024-11-26 Thread fabioromano1
On Tue, 26 Nov 2024 15:02:20 GMT, Raffaello Giulietti wrote: > OK. But for the sake of completeness, I would add at least one test case for > an overflowing `workingScale`. I'm afraid it's not possible to produce such a test case, with the current implementation of `BigInteger`. Indeed, `work

Re: RFR: 8341402: BigDecimal's square root optimization [v23]

2024-11-26 Thread Raffaello Giulietti
On Tue, 26 Nov 2024 14:51:44 GMT, fabioromano1 wrote: >> test/jdk/java/math/BigDecimal/SquareRootTests.java line 200: >> >>> 198: // mc.roundingMode != RoundingMode.UNNECESSARY && >>> mc.precision == 0 >>> 199: try { >>> 200: result = BigDecimal.TEN.sqrt(

Re: RFR: 8341402: BigDecimal's square root optimization [v23]

2024-11-26 Thread fabioromano1
On Tue, 26 Nov 2024 14:08:23 GMT, Raffaello Giulietti wrote: >> fabioromano1 has updated the pull request incrementally with one additional >> commit since the last revision: >> >> Added tests for exact results path > > test/jdk/java/math/BigDecimal/SquareRootTests.java line 200: > >> 198:

Re: RFR: 8341402: BigDecimal's square root optimization [v23]

2024-11-26 Thread Raffaello Giulietti
On Mon, 25 Nov 2024 19:36:04 GMT, fabioromano1 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 i

Re: RFR: 8341402: BigDecimal's square root optimization [v23]

2024-11-25 Thread fabioromano1
> 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 >

Re: RFR: 8341402: BigDecimal's square root optimization [v20]

2024-11-22 Thread fabioromano1
On Fri, 22 Nov 2024 14:21:50 GMT, Raffaello Giulietti wrote: > Not sure if you are planning to make other code changes before adding the > tests? From my perspective, the current status of the code looks good. No, I'm not planning to make other changes, I will add the tests soon.

Re: RFR: 8341402: BigDecimal's square root optimization [v20]

2024-11-22 Thread Raffaello Giulietti
On Tue, 19 Nov 2024 19:48:25 GMT, Raffaello Giulietti wrote: >> Yes, indeed in this case the remainder is always needed, so invoking >> `workingInt.sqrtAndRemainder()` is faster than checking >> `!workingInt.equals(sqrt.multiply(sqrt))`, as it avoids the squaring of >> `sqrt`. > > I see. > >

Re: RFR: 8341402: BigDecimal's square root optimization [v17]

2024-11-20 Thread fabioromano1
On Tue, 19 Nov 2024 09:21:08 GMT, Raffaello Giulietti wrote: > While you are at it, it would be useful to add one test for each of the paths > in the new algorithm (including the exception cases) in the existing > [SquareRootTests](https://github.com/openjdk/jdk/blob/master/test/jdk/java/math/

Re: RFR: 8341402: BigDecimal's square root optimization [v22]

2024-11-20 Thread fabioromano1
> 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 >

Re: RFR: 8341402: BigDecimal's square root optimization [v21]

2024-11-20 Thread fabioromano1
> 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 >

Re: RFR: 8341402: BigDecimal's square root optimization [v20]

2024-11-20 Thread Raffaello Giulietti
On Tue, 19 Nov 2024 18:44:51 GMT, Raffaello Giulietti wrote: >> fabioromano1 has updated the pull request incrementally with one additional >> commit since the last revision: >> >> Correct remainder checking > > src/java.base/share/classes/java/math/BigDecimal.java line 2260: > >> 2258:

Re: RFR: 8341402: BigDecimal's square root optimization [v20]

2024-11-19 Thread fabioromano1
On Tue, 19 Nov 2024 18:43:46 GMT, Raffaello Giulietti wrote: >> fabioromano1 has updated the pull request incrementally with one additional >> commit since the last revision: >> >> Correct remainder checking > > src/java.base/share/classes/java/math/BigDecimal.java line 2200: > >> 2198:

Re: RFR: 8341402: BigDecimal's square root optimization [v20]

2024-11-19 Thread Raffaello Giulietti
On Tue, 19 Nov 2024 19:02:09 GMT, fabioromano1 wrote: >> src/java.base/share/classes/java/math/BigDecimal.java line 2253: >> >>> 2251: >>> 2252: case UP, CEILING -> { >>> 2253: BigInteger[] sqrtRem = >>> workingInt.sqrtAndRemainder(); >> >> Can't th

Re: RFR: 8341402: BigDecimal's square root optimization [v20]

2024-11-19 Thread fabioromano1
On Tue, 19 Nov 2024 18:44:27 GMT, Raffaello Giulietti wrote: >> fabioromano1 has updated the pull request incrementally with one additional >> commit since the last revision: >> >> Correct remainder checking > > src/java.base/share/classes/java/math/BigDecimal.java line 2253: > >> 2251: >>

Re: RFR: 8341402: BigDecimal's square root optimization [v20]

2024-11-19 Thread Raffaello Giulietti
On Tue, 19 Nov 2024 14:44:40 GMT, fabioromano1 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 i

Re: RFR: 8341402: BigDecimal's square root optimization [v20]

2024-11-19 Thread fabioromano1
> 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 >

Re: RFR: 8341402: BigDecimal's square root optimization [v19]

2024-11-19 Thread fabioromano1
> 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 >

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

2024-11-19 Thread fabioromano1
> 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 >

Re: RFR: 8341402: BigDecimal's square root optimization [v17]

2024-11-19 Thread Raffaello Giulietti
On Mon, 18 Nov 2024 14:21:29 GMT, Raffaello Giulietti wrote: >> src/java.base/share/classes/java/math/BigDecimal.java line 2248: >> >>> 2246: } >>> 2247: } >>> 2248: } else { // mc.roundingMode == RoundingMode.UP || >>> mc

Re: RFR: 8341402: BigDecimal's square root optimization [v17]

2024-11-18 Thread Raffaello Giulietti
On Mon, 18 Nov 2024 14:11:43 GMT, Raffaello Giulietti wrote: >> fabioromano1 has updated the pull request incrementally with one additional >> commit since the last revision: >> >> Optimize sqrt branch for exact results > > src/java.base/share/classes/java/math/BigDecimal.java line 2248: >

Re: RFR: 8341402: BigDecimal's square root optimization [v17]

2024-11-18 Thread Raffaello Giulietti
On Fri, 15 Nov 2024 14:21:21 GMT, fabioromano1 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 i

Re: RFR: 8341402: BigDecimal's square root optimization [v17]

2024-11-15 Thread fabioromano1
> 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 >

Re: RFR: 8341402: BigDecimal's square root optimization [v16]

2024-11-15 Thread fabioromano1
On Fri, 15 Nov 2024 13:22:32 GMT, Raffaello Giulietti wrote: >> fabioromano1 has updated the pull request incrementally with one additional >> commit since the last revision: >> >> Code simplification > > src/java.base/share/classes/java/math/BigDecimal.java line 2190: > >> 2188:

Re: RFR: 8341402: BigDecimal's square root optimization [v16]

2024-11-15 Thread Raffaello Giulietti
On Tue, 22 Oct 2024 14:07:30 GMT, fabioromano1 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 i

Re: RFR: 8341402: BigDecimal's square root optimization

2024-11-13 Thread Raffaello Giulietti
On Mon, 21 Oct 2024 17:01:43 GMT, fabioromano1 wrote: >>> > Curiously, this one runs in a fraction of a second on the current >>> > implementation, but not on the proposed one: >>> > `BigDecimal.valueOf(100).sqrt(new MathContext(1_000_000, >>> > RoundingMode.HALF_EVEN)).shortValue()` >>> >>>

Re: RFR: 8341402: BigDecimal's square root optimization

2024-11-13 Thread fabioromano1
On Wed, 13 Nov 2024 16:07:42 GMT, Raffaello Giulietti wrote: >>> Since there's an invocation of `stripTrailingZeros()` anyway, what's the >>> reason to _not_ "optimize" for other round modes as well, like in the >>> current implementation? >> >> Because it is not necessary to strip zeros when

Re: RFR: 8341402: BigDecimal's square root optimization [v16]

2024-10-22 Thread fabioromano1
> 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 >

Re: RFR: 8341402: BigDecimal's square root optimization [v15]

2024-10-22 Thread fabioromano1
> 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 >

Re: RFR: 8341402: BigDecimal's square root optimization [v14]

2024-10-22 Thread fabioromano1
> 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 >

Re: RFR: 8341402: BigDecimal's square root optimization [v13]

2024-10-22 Thread fabioromano1
> 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 >

Re: RFR: 8341402: BigDecimal's square root optimization [v12]

2024-10-22 Thread fabioromano1
> 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 >

Re: RFR: 8341402: BigDecimal's square root optimization [v11]

2024-10-22 Thread fabioromano1
> 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 >

Re: RFR: 8341402: BigDecimal's square root optimization [v10]

2024-10-21 Thread fabioromano1
> 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 >

Re: RFR: 8341402: BigDecimal's square root optimization [v9]

2024-10-21 Thread fabioromano1
> 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 >

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

2024-10-21 Thread Raffaello Giulietti
On Mon, 21 Oct 2024 17:32:33 GMT, fabioromano1 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 i

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

2024-10-21 Thread fabioromano1
> 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 >

Re: RFR: 8341402: BigDecimal's square root optimization

2024-10-21 Thread fabioromano1
On Mon, 21 Oct 2024 16:47:36 GMT, Raffaello Giulietti wrote: > Since there's an invocation of `stripTrailingZeros()` anyway, what's the > reason to _not_ "optimize" for other round modes as well, like in the current > implementation? Because it is not necessary to strip zeros when an exact re

Re: RFR: 8341402: BigDecimal's square root optimization

2024-10-21 Thread Raffaello Giulietti
On Wed, 2 Oct 2024 16:43:11 GMT, fabioromano1 wrote: > > Curiously, this one runs in a fraction of a second on the current > > implementation, but not on the proposed one: > > `BigDecimal.valueOf(100).sqrt(new MathContext(1_000_000, > > RoundingMode.HALF_EVEN)).shortValue()` > > @rgiulietti T

Re: RFR: 8341402: BigDecimal's square root optimization [v2]

2024-10-21 Thread fabioromano1
On Thu, 3 Oct 2024 00:47:23 GMT, Joe Darcy wrote: > My initial question is what additional regression test cases should be added > to probe the new code. @rgiulietti @jddarcy This should be the path tree for the test cases of the algorithm, whether `signum == 1`: If `mc.roundingMode == Roundi

Re: RFR: 8341402: BigDecimal's square root optimization [v7]

2024-10-21 Thread fabioromano1
> 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 >

Re: RFR: 8341402: BigDecimal's square root optimization [v6]

2024-10-21 Thread fabioromano1
> 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 >

Re: RFR: 8341402: BigDecimal's square root optimization [v5]

2024-10-21 Thread fabioromano1
> 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 >

Re: RFR: 8341402: BigDecimal's square root optimization [v4]

2024-10-04 Thread fabioromano1
> 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 >

Re: RFR: 8341402: BigDecimal's square root optimization [v3]

2024-10-04 Thread fabioromano1
> 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 >

Re: RFR: 8341402: BigDecimal's square root optimization [v2]

2024-10-03 Thread Raffaello Giulietti
On Thu, 3 Oct 2024 12:30:20 GMT, fabioromano1 wrote: >> I'll open a JBS issue to refer to as soon as you open the new PR. >> >> Please keep the first PR comment as short as possible, then add further >> details in another comment. As only the first comment is auto-copied in >> every email in t

Re: RFR: 8341402: BigDecimal's square root optimization [v2]

2024-10-03 Thread fabioromano1
On Thu, 3 Oct 2024 09:18:56 GMT, Raffaello Giulietti wrote: >> @fabioromano1 I agree with starting a new PR for speed up >> `stripZerosToMatchScale()`. > > I'll open a JBS issue to refer to as soon as you open the new PR. > > Please keep the first PR comment as short as possible, then add furt

Re: RFR: 8341402: BigDecimal's square root optimization [v2]

2024-10-03 Thread Raffaello Giulietti
On Thu, 3 Oct 2024 09:10:07 GMT, fabioromano1 wrote: >> @rgiulietti I tried to implement and test stripping zeros algorithm with >> repeated squares trick, and on my laptop it takes around two seconds for >> strip one million of zeros. So, I decided to remove the method >> `stripZerosToEvenS

Re: RFR: 8341402: BigDecimal's square root optimization [v2]

2024-10-03 Thread fabioromano1
On Thu, 3 Oct 2024 07:55:26 GMT, fabioromano1 wrote: >> Without experimenting a bit, it's hard to tell. >> Anyway, I believe the current implementation of `stripZerosToMatchScale()` >> is O(n^2) rather than exponential, because each single division by 10 is >> linear. >> >> But let's focus on

Re: RFR: 8341402: BigDecimal's square root optimization [v2]

2024-10-03 Thread Raffaello Giulietti
On Thu, 3 Oct 2024 07:55:26 GMT, fabioromano1 wrote: >> Without experimenting a bit, it's hard to tell. >> Anyway, I believe the current implementation of `stripZerosToMatchScale()` >> is O(n^2) rather than exponential, because each single division by 10 is >> linear. >> >> But let's focus on

Re: RFR: 8341402: BigDecimal's square root optimization [v2]

2024-10-03 Thread fabioromano1
On Wed, 2 Oct 2024 18:16:06 GMT, Raffaello Giulietti wrote: >> A possible faster implementation of `stripZerosToMatchScale()` could be >> based on dividing by increasing powers of 10 whose exponent doubles at each >> step (a kind of repeated squares trick), although the asymptotic running >>

Re: RFR: 8341402: BigDecimal's square root optimization [v2]

2024-10-02 Thread Joe Darcy
On Thu, 3 Oct 2024 00:05:17 GMT, fabioromano1 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 in

Re: RFR: 8341402: BigDecimal's square root optimization [v2]

2024-10-02 Thread fabioromano1
> 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 >

Re: RFR: 8341402: BigDecimal's square root optimization

2024-10-02 Thread fabioromano1
On Wed, 2 Oct 2024 18:16:06 GMT, Raffaello Giulietti wrote: > Without experimenting a bit, it's hard to tell. Anyway, I believe the current > implementation of `stripZerosToMatchScale()` is O(n^2) rather than > exponential, because each single division by 10 is linear. > > But let's focus on

Re: RFR: 8341402: BigDecimal's square root optimization

2024-10-02 Thread Raffaello Giulietti
On Wed, 2 Oct 2024 18:06:57 GMT, fabioromano1 wrote: >> After looking at the code more closely, these are _not_ the reasons for the >> long running times of my example above. >> Neither the computation of the large power of 10, nor the multiplication, >> nor the `BigInteger` square root are slo

Re: RFR: 8341402: BigDecimal's square root optimization

2024-10-02 Thread fabioromano1
On Wed, 2 Oct 2024 17:37:03 GMT, Raffaello Giulietti wrote: >> @rgiulietti The only solution I can think of to avoid this is to reimplement >> Zimmerman's square root algorithm in the class `BigDecimal`, using the radix >> 10 representation of the number's magnitude. > > After looking at the c

Re: RFR: 8341402: BigDecimal's square root optimization

2024-10-02 Thread Raffaello Giulietti
On Wed, 2 Oct 2024 16:32:47 GMT, fabioromano1 wrote: >> src/java.base/share/classes/java/math/BigDecimal.java line 2213: >> >>> 2211: >>> 2212: BigDecimal working = new BigDecimal(this.intVal, >>> this.intCompact, (int) workingScale, this.precision); >>> 2213: B

Re: RFR: 8341402: BigDecimal's square root optimization

2024-10-02 Thread fabioromano1
On Wed, 2 Oct 2024 13:44:42 GMT, Raffaello Giulietti wrote: > Curiously, this one runs in a fraction of a second on the current > implementation, but not on the proposed one: > `BigDecimal.valueOf(100).sqrt(new MathContext(1_000_000, > RoundingMode.HALF_EVEN)).shortValue()` @rgiulietti This

Re: RFR: 8341402: BigDecimal's square root optimization

2024-10-02 Thread fabioromano1
On Wed, 2 Oct 2024 16:15:29 GMT, fabioromano1 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 in

Re: RFR: 8341402: BigDecimal's square root optimization

2024-10-02 Thread fabioromano1
On Wed, 2 Oct 2024 10:31:09 GMT, fabioromano1 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

Re: RFR: 8341402: BigDecimal's square root optimization

2024-10-02 Thread Raffaello Giulietti
On Wed, 2 Oct 2024 10:31:09 GMT, fabioromano1 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

Re: RFR: 8341402: BigDecimal's square root optimization

2024-10-02 Thread fabioromano1
On Wed, 2 Oct 2024 13:49:29 GMT, Raffaello Giulietti 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

Re: RFR: 8341402: BigDecimal's square root optimization

2024-10-02 Thread Raffaello Giulietti
On Wed, 2 Oct 2024 10:31:09 GMT, fabioromano1 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

Re: RFR: 8341402: BigDecimal's square root optimization

2024-10-02 Thread Raffaello Giulietti
On Wed, 2 Oct 2024 10:31:09 GMT, fabioromano1 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

RFR: 8341402: BigDecimal's square root optimization

2024-10-02 Thread fabioromano1
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(