RFR: [type-classes] JDK-8376823: Add prototype polynomial class [v3]

Chen Liang liach at openjdk.org
Sat Jan 31 23:09:26 UTC 2026


On Sat, 31 Jan 2026 19:17:51 GMT, Joe Darcy <darcy at openjdk.org> wrote:

>> Add a simple polynomial class over doubles as an example of a ring.
>
> Joe Darcy has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Add divide and remainder implementations.

Just curious, are we planning to experience with a more generic polynomial that takes an eligible numerical type, like ones that take float or textbook imaginary?

src/java.base/share/classes/java/math/PolynomialDouble.java line 174:

> 172:             return (i == 0) ?
> 173:                 ZERO :
> 174:                 new PolynomialDouble(Arrays.copyOf(coeffs, i));

Let's defensively copy coeffs before checking for zero - the check and the copy might read different values for `coeffs[i - 1]` if the coeffs is updated by another thread.

src/java.base/share/classes/java/math/PolynomialDouble.java line 283:

> 281:         }
> 282: 
> 283:         double[] tmp = new double[Math.max(x.length, y.length)];

Suggestion:

        double[] tmp = new double[x.length];

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

PR Review: https://git.openjdk.org/valhalla/pull/2004#pullrequestreview-3733822351
PR Review Comment: https://git.openjdk.org/valhalla/pull/2004#discussion_r2750148884
PR Review Comment: https://git.openjdk.org/valhalla/pull/2004#discussion_r2750149954


More information about the valhalla-dev mailing list