mirror of
https://github.com/apache/commons-math.git
synced 2025-02-08 11:05:56 +00:00
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:
parent
fe761c28ce
commit
2123f7805b
@ -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());
|
||||
}
|
||||
|
@ -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>
|
||||
|
@ -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()));
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user