commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r1146573 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/complex/Complex.java site/xdoc/changes.xml test/java/org/apache/commons/math/complex/ComplexTest.java
Date Thu, 14 Jul 2011 06:08:06 GMT
Author: psteitz
Date: Thu Jul 14 06:08:05 2011
New Revision: 1146573

URL: http://svn.apache.org/viewvc?rev=1146573&view=rev
Log:
Fixed add method to match javadoc contract when one or both addends has NaN parts.

JIRA: MATH-618
Reported by Arne Plose

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/complex/Complex.java
    commons/proper/math/trunk/src/site/xdoc/changes.xml
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/complex/ComplexTest.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/complex/Complex.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/complex/Complex.java?rev=1146573&r1=1146572&r2=1146573&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/complex/Complex.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/complex/Complex.java Thu
Jul 14 06:08:05 2011
@@ -150,6 +150,9 @@ public class Complex implements FieldEle
     public Complex add(Complex rhs)
         throws NullArgumentException {
         MathUtils.checkNotNull(rhs);
+        if (isNaN || rhs.isNaN) {
+            return NaN;
+        }
         return createComplex(real + rhs.getReal(),
             imaginary + rhs.getImaginary());
     }

Modified: commons/proper/math/trunk/src/site/xdoc/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/site/xdoc/changes.xml?rev=1146573&r1=1146572&r2=1146573&view=diff
==============================================================================
--- commons/proper/math/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/trunk/src/site/xdoc/changes.xml Thu Jul 14 06:08:05 2011
@@ -52,6 +52,11 @@ The <action> type attribute can be add,u
     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>

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/complex/ComplexTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/complex/ComplexTest.java?rev=1146573&r1=1146572&r2=1146573&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/complex/ComplexTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/complex/ComplexTest.java
Thu Jul 14 06:08:05 2011
@@ -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()));
     }
 



Mime
View raw message