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

Raffaello Giulietti rgiulietti at openjdk.org
Thu Nov 6 19:11:09 UTC 2025


On Wed, 29 Oct 2025 11:48:04 GMT, fabioromano1 <duke at openjdk.org> wrote:

>> src/java.base/share/classes/java/math/BigDecimal.java line 1794:
>> 
>>> 1792:         if (this.signum() == 0) // 0/y
>>> 1793:             return zeroValueOf(preferredScale);
>>> 1794:         else {
>> 
>> The old algorithm has relatively few paths through it for different arguments.
>> 
>> Do the existing test cases provide adequate coverage of the new set of code paths?
>
> I think they do, @rgiulietti do you think the test coverage is adequate?

Sorry @fabioromano1 for being late.

>From what I see, the tests that involve terminating quotients are in `powersOf2and5()` and `properScaleTests()`.

I would add a specific additional test method where dividends and divisors are not just of the form 2^e2 ⋅ 5^e5, but a bit more general, like 21⋅10^3 / 140⋅10^6 and similar.
The test cases should exercise the implementation's cases of e2 ≤ e5, e2 > e5, `scaleDiff` in the `int` range and outside (in both directions), and maybe even some cases where the theoretical quotient is terminating but where limits are exceeded, leading to exceptions that need to be caught in the test.

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

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


More information about the core-libs-dev mailing list