JDK-8364045 : Release Note: Method `BigDecimal.sqrt()` Might Now Throw on Powers of 100 and Huge Precisions
  • Type: Sub-task
  • Component: core-libs
  • Sub-Component: java.math
  • Affected Version: 25
  • Priority: P4
  • Status: New
  • Resolution: Unresolved
  • Submitted: 2025-07-24
  • Updated: 2025-07-24
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
25Unresolved
Description
The method `BigDecimal.sqrt()` has been reimplemented to perform much better.

However, in some very rare and quite artificial cases involving powers of 100 and huge precisions, the new implementation throws whereas the old one returns a result.

For example
```
BigDecimal.valueOf(100).sqrt(new MathContext(1_000_000_000, RoundingMode.UP))
```
returns `10` in the old implementation.
Note, however, that rather than returning `11`, it throws when evaluating
```
BigDecimal.valueOf(121).sqrt(new MathContext(1_000_000_000, RoundingMode.UP))
```

Indeed, the old implementation treats powers of 100 as special cases (see 1st example). Other exact squares are treated normally, so throw when the requested precision is too high (see 2nd example). This special behavior for powers of 100 is not recommended, as it is more confusing than helpful when compared to other exact squares.

The new implementation is agnostic about powers of 100, and throws whenever internal intermediate results would exceed supported ranges. In particular, it uniformly throws on both the examples above.
Comments
[~darcy] A release note about the special handling of powers of 100 in the old implementation which has been suppressed in the new one.
24-07-2025