RFR: [type-classes] JDK-8376823: Add prototype polynomial class [v3]
Joe Darcy
darcy at openjdk.org
Sat Jan 31 23:19:02 UTC 2026
On Sat, 31 Jan 2026 23:07:00 GMT, Chen Liang <liach at openjdk.org> wrote:
> 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?
Yes, long-term that is a possibility -- that was part of the motivation for naming the class "PolynomialDouble" rather than just "Polynomial." Conceptually, Polynomial<N extends Numeric> would make sense, perhaps with some mild side-conditions on Numerics.
> 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.
Yeah, meant to do that, TOCTOU and all that. Thanks.
-------------
PR Comment: https://git.openjdk.org/valhalla/pull/2004#issuecomment-3829560235
PR Review Comment: https://git.openjdk.org/valhalla/pull/2004#discussion_r2750162898
More information about the valhalla-dev
mailing list