Fixed add method to match javadoc contract when one or both addends has NaN parts.

JIRA: MATH-618
Reported by Arne Plose

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1146573 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Phil Steitz 2011-07-14 06:08:05 +00:00
parent fe761c28ce
commit 2123f7805b
3 changed files with 9 additions and 1 deletions

View File

@ -150,6 +150,9 @@ public class Complex implements FieldElement<Complex>, Serializable {
public Complex add(Complex rhs)
throws NullArgumentException {
MathUtils.checkNotNull(rhs);
if (isNaN || rhs.isNaN) {
return NaN;
}
return createComplex(real + rhs.getReal(),
imaginary + rhs.getImaginary());
}

View File

@ -52,6 +52,11 @@ The <action> type attribute can be add,update,fix,remove.
If the output is not quite correct, check for invisible trailing spaces!
-->
<release version="3.0" date="TBD" description="TBD">
<action dev="psteitz" type="fix" issue="MATH-618" due-to="Arne Plose">
Complex add javadoc says that if either addend has NaN parts, the result
should be Complex.NaN. Prior to the fix for this issue, NaNs were propagated
only in real and imaginary parts individually.
</action>
<action dev="erans" type="add" issue="MATH-581" due-to="Sébastien Brisard">
Framework for iterative linear solvers.
</action>

View File

@ -113,7 +113,7 @@ public class ComplexTest {
Assert.assertTrue(z.isNaN());
z = new Complex(1, nan);
Complex w = x.add(z);
Assert.assertEquals(w.getReal(), 4.0, 0);
Assert.assertTrue(Double.isNaN(w.getReal()));
Assert.assertTrue(Double.isNaN(w.getImaginary()));
}