diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 64fb6fdb3..b6f8c5405 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -52,6 +52,9 @@ If the output is not quite correct, check for invisible trailing spaces!
+
+ Allow unlimited input values for "Dfp#multiply(int)".
+
Added distance to point to 2D Line and Segment.
diff --git a/src/main/java/org/apache/commons/math3/dfp/Dfp.java b/src/main/java/org/apache/commons/math3/dfp/Dfp.java
index d278a3128..3a9198271 100644
--- a/src/main/java/org/apache/commons/math3/dfp/Dfp.java
+++ b/src/main/java/org/apache/commons/math3/dfp/Dfp.java
@@ -1595,12 +1595,24 @@ public class Dfp implements FieldElement {
}
- /** Multiply this by a single digit 0<=x<radix.
- * There are speed advantages in this special case
+ /** Multiply this by a single digit x.
* @param x multiplicand
* @return product of this and x
*/
public Dfp multiply(final int x) {
+ if (x >= 0 && x < RADIX) {
+ return multiplyFast(x);
+ } else {
+ return multiply(newInstance(x));
+ }
+ }
+
+ /** Multiply this by a single digit 0<=x<radix.
+ * There are speed advantages in this special case.
+ * @param x multiplicand
+ * @return product of this and x
+ */
+ private Dfp multiplyFast(final int x) {
Dfp result = newInstance(this);
/* handle special cases */
diff --git a/src/test/java/org/apache/commons/math3/dfp/DfpTest.java b/src/test/java/org/apache/commons/math3/dfp/DfpTest.java
index f7549764f..6f224665c 100644
--- a/src/test/java/org/apache/commons/math3/dfp/DfpTest.java
+++ b/src/test/java/org/apache/commons/math3/dfp/DfpTest.java
@@ -906,13 +906,17 @@ public class DfpTest {
nan,
0, "Multiply #36");
- test(field.newDfp("1").multiply(10000), // out of range
- nan,
- DfpField.FLAG_INVALID, "Multiply #37");
+ test(field.newDfp("1").multiply(10000),
+ field.newDfp("10000"),
+ 0, "Multiply #37");
- test(field.newDfp("1").multiply(-1), // out of range
- nan,
- DfpField.FLAG_INVALID, "Multiply #38");
+ test(field.newDfp("2").multiply(1000000),
+ field.newDfp("2000000"),
+ 0, "Multiply #38");
+
+ test(field.newDfp("1").multiply(-1),
+ field.newDfp("-1"),
+ 0, "Multiply #39");
}
@Test