You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by tn...@apache.org on 2012/10/21 18:22:50 UTC
svn commit: r1400671 - in /commons/proper/math/trunk/src:
changes/changes.xml main/java/org/apache/commons/math3/dfp/Dfp.java
test/java/org/apache/commons/math3/dfp/DfpTest.java
Author: tn
Date: Sun Oct 21 16:22:50 2012
New Revision: 1400671
URL: http://svn.apache.org/viewvc?rev=1400671&view=rev
Log:
[MATH-778] Allow unlimited input values for Dfp#multiply.
Modified:
commons/proper/math/trunk/src/changes/changes.xml
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/dfp/Dfp.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/dfp/DfpTest.java
Modified: commons/proper/math/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/changes/changes.xml?rev=1400671&r1=1400670&r2=1400671&view=diff
==============================================================================
--- commons/proper/math/trunk/src/changes/changes.xml (original)
+++ commons/proper/math/trunk/src/changes/changes.xml Sun Oct 21 16:22:50 2012
@@ -52,6 +52,9 @@ If the output is not quite correct, chec
<body>
<release version="3.1" date="TBD" description="
">
+ <action dev="tn" type="fix" issue="MATH-778" due-to="Sébastien Brisard">
+ Allow unlimited input values for "Dfp#multiply(int)".
+ </action>
<action dev="luc" type="fix" issue="MATH-641" due-to="Curtis Jensen">
Added distance to point to 2D Line and Segment.
</action>
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/dfp/Dfp.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/dfp/Dfp.java?rev=1400671&r1=1400670&r2=1400671&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/dfp/Dfp.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/dfp/Dfp.java Sun Oct 21 16:22:50 2012
@@ -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 */
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/dfp/DfpTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/dfp/DfpTest.java?rev=1400671&r1=1400670&r2=1400671&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/dfp/DfpTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/dfp/DfpTest.java Sun Oct 21 16:22:50 2012
@@ -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("2").multiply(1000000),
+ field.newDfp("2000000"),
+ 0, "Multiply #38");
- test(field.newDfp("1").multiply(-1), // out of range
- nan,
- DfpField.FLAG_INVALID, "Multiply #38");
+ test(field.newDfp("1").multiply(-1),
+ field.newDfp("-1"),
+ 0, "Multiply #39");
}
@Test