You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ps...@apache.org on 2009/10/27 02:32:20 UTC

svn commit: r830044 - 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

Author: psteitz
Date: Tue Oct 27 01:32:19 2009
New Revision: 830044

URL: http://svn.apache.org/viewvc?rev=830044&view=rev
Log:
Removed dead code, improved test coverage.  Dead code pointed out in JIRA: MATH-306. Thanks to Joerg Huber.

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=830044&r1=830043&r2=830044&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 Tue Oct 27 01:32:19 2009
@@ -177,7 +177,7 @@
      * <pre><code>
      *    a + bi          ac + bd + (bc - ad)i
      *    ----------- = -------------------------
-     *    c + di               c<sup>2</sup> + d<sup>2</sup>
+     *    c + di         c<sup>2</sup> + d<sup>2</sup>
      * </code></pre>
      * but uses
      * <a href="http://doi.acm.org/10.1145/1039813.1039814">
@@ -221,17 +221,11 @@
         }
 
         if (Math.abs(c) < Math.abs(d)) {
-            if (d == 0.0) {
-                return createComplex(real/c, imaginary/c);
-            }
             double q = c / d;
             double denominator = c * q + d;
             return createComplex((real * q + imaginary) / denominator,
                 (imaginary * q - real) / denominator);
         } else {
-            if (c == 0.0) {
-                return createComplex(imaginary/d, -real/c);
-            }
             double q = d / c;
             double denominator = d * q + c;
             return createComplex((imaginary * q + real) / denominator,

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=830044&r1=830043&r2=830044&view=diff
==============================================================================
--- commons/proper/math/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/trunk/src/site/xdoc/changes.xml Tue Oct 27 01:32:19 2009
@@ -39,6 +39,9 @@
   </properties>
   <body>
     <release version="2.1" date="TBD" description="TBD">
+      <action dev="psteitz" type="fix" issue="MATH-306" due-to="Joerg Huber">
+        Removed dead code from Complex#divide.
+      </action>
       <action dev="psteitz" tyoe="fix" issue="MATH-294">
         Fixed implementation of RandomDataImpl#nextPoisson by implementing an alternative
         algorithm for large means.

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=830044&r1=830043&r2=830044&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 Tue Oct 27 01:32:19 2009
@@ -144,6 +144,19 @@
         assertEquals(39.0 / 61.0, z.getReal(), 1.0e-5);
         assertEquals(2.0 / 61.0, z.getImaginary(), 1.0e-5);
     }
+    
+    public void testDivideReal() {
+        Complex x = new Complex(2d, 3d);
+        Complex y = new Complex(2d, 0d);
+        assertEquals(new Complex(1d, 1.5), x.divide(y));
+        
+    }
+    
+    public void testDivideImaginary() {
+        Complex x = new Complex(2d, 3d);
+        Complex y = new Complex(0d, 2d);
+        assertEquals(new Complex(1.5d, -1d), x.divide(y));
+    }
 
     public void testDivideInfinite() {
         Complex x = new Complex(3, 4);
@@ -164,6 +177,12 @@
         assertTrue(Double.isNaN(z.getReal()));
         assertTrue(Double.isNaN(z.getImaginary()));
     }
+    
+    public void testDivideZero() {
+        Complex x = new Complex(3.0, 4.0);
+        Complex z = x.divide(Complex.ZERO);
+        assertEquals(z, Complex.NaN);
+    }
 
     public void testDivideNaN() {
         Complex x = new Complex(3.0, 4.0);