-
Sub-task
-
Resolution: Delivered
-
P4
-
25
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.
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.