RFR: 8367603: Optimize exact division in BigDecimal [v17]

Raffaello Giulietti rgiulietti at openjdk.org
Fri Sep 26 13:11:36 UTC 2025


On Fri, 26 Sep 2025 07:34:55 GMT, fabioromano1 <duke at openjdk.org> wrote:

>> A formula to lower the overestimate for the precision of an exact quotient, without introducing too expensive operations of division on numerator and denominator.
>
> fabioromano1 has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Minor change

src/java.base/share/classes/java/math/BigDecimal.java line 1802:

> 1800:         /* The technique used is the following:
> 1801:          * take a/b, compute b' = b/(2^p2 5^p5), where
> 1802:          * p2 = max{n | b ≡ 0 mod 2^n} and p5 = max{n | b ≡ 0 mod 5^n}.

These are exponents, not powers, so maybe `e2`, `e5`, `e10` are better names?

test/micro/org/openjdk/bench/java/math/BigDecimalDivide.java line 60:

> 58: 
> 59:         xsArray = new BigDecimal[TESTSIZE][2]; /*
> 60:          * Each array entry is atmost 64 bits

Suggestion:

         * Each array entry is at most 64 bits

and similar typos down below

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

PR Review Comment: https://git.openjdk.org/jdk/pull/27271#discussion_r2382374210
PR Review Comment: https://git.openjdk.org/jdk/pull/27271#discussion_r2382377691


More information about the core-libs-dev mailing list