RFR: 8341402: BigDecimal's square root optimization

Raffaello Giulietti rgiulietti at openjdk.org
Mon Oct 21 16:50:25 UTC 2024


On Wed, 2 Oct 2024 16:43:11 GMT, fabioromano1 <duke at openjdk.org> 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 is because, in the current implementation, the check for even powers of 10 is always done, while in mine is done only if exact result is required.

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?

-------------

PR Comment: https://git.openjdk.org/jdk/pull/21301#issuecomment-2427205252


More information about the core-libs-dev mailing list