[MATH-778] Allow unlimited input values for Dfp#multiply.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1400671 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Thomas Neidhart 2012-10-21 16:22:50 +00:00
parent 0912bac520
commit 5b9302d5be
3 changed files with 27 additions and 8 deletions

View File

@ -52,6 +52,9 @@ If the output is not quite correct, check for invisible trailing spaces!
<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>

View File

@ -1595,12 +1595,24 @@ public class Dfp implements FieldElement<Dfp> {
}
/** Multiply this by a single digit 0&lt;=x&lt;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&lt;=x&lt;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 */

View File

@ -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