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

fabioromano1 duke at openjdk.org
Tue Nov 26 17:08:51 UTC 2024


On Tue, 26 Nov 2024 15:02:20 GMT, Raffaello Giulietti <rgiulietti at openjdk.org> 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, `workingScale` is defined by `workingScale = this.scale - normScale`, and `normScale` by:

long normScale = minWorkingPrec - this.precision() + this.scale;
normScale += normScale & 1L;

Therefore `workingScale ==  this.precision() - minWorkingPrec - (normScale & 1L)`, so to overflow `workingScale` it is necessary to maximize `this.precision()`, thus`this.intVal` must have at least `Integer.MAX_VALUE + 1` digits, but `BigInteger.TEN.pow(Integer.MAX_VALUE)` surely exceeds the supported range for  `BigInteger`s...

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

PR Review Comment: https://git.openjdk.org/jdk/pull/21301#discussion_r1858931814


More information about the core-libs-dev mailing list