JDK-8341402 : BigDecimal's square root optimization
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.math
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2024-10-02
  • Updated: 2025-05-21
  • Resolved: 2025-04-10
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 25
25 b19Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Description
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



Comments
Changeset: c4c3edfa Branch: master Author: fabioromano1 <51378941+fabioromano1@users.noreply.github.com> Committer: Raffaello Giulietti <rgiulietti@openjdk.org> Date: 2025-04-10 14:34:52 +0000 URL: https://git.openjdk.org/jdk/commit/c4c3edfa964ef504f12971c5deef7c7355bdf325
10-04-2025

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk/pull/21301 Date: 2024-10-02 10:31:09 +0000
02-10-2024

Moving to JDK for further evaluation.
02-10-2024