insaf021 opened a new pull request, #359:
URL: https://github.com/apache/commons-math/pull/359
Reproduced on master, JDK 21:
new DfpField(10).newDfp(12345678901234567L)
java.lang.ArrayIndexOutOfBoundsException: arraycopy: destination index
-1 out of bounds for int[4]
`Dfp(DfpField, long)` shifts each radix digit into the mantissa with
`System.arraycopy` and never checks `exp` against `mant.length`. Any `DfpField`
below 17 decimal digits has 4 radix digits (16 decimal), but a long needs up to
5, so every `|x| >= 10^16` overruns, `Long.MAX_VALUE` and `Long.MIN_VALUE`
included. `DfpField.newDfp(long)` and `Dfp.newInstance(long)` both land here,
whereas `newDfp("12345678901234567")` on the same field rounds to the precision
as expected.
Once the mantissa is full, the least significant digit is now shifted out
and the value is rounded with it through `round()`, the same path the string
constructor uses. The `Long.MIN_VALUE` +1 correction goes to that digit when
one was dropped. Fields of 17 or more digits take the old path unchanged.
`testLongConstructorBeyondPrecision` in `DfpTest` checks that the long and
string constructors agree on a 10-digit field. It fails on master with the
exception above and passes with the fix; `mvn clean verify javadoc:javadoc` on
legacy-core is green.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]