commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r1150433 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/complex/Complex.java test/java/org/apache/commons/math/complex/ComplexTest.java
Date Sun, 24 Jul 2011 16:45:07 GMT
Author: psteitz
Date: Sun Jul 24 16:45:06 2011
New Revision: 1150433

URL: http://svn.apache.org/viewvc?rev=1150433&view=rev
Log:
Made scalar division consistent with complex division wrt infinite arguments, improved tests.

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/complex/Complex.java
    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=1150433&r1=1150432&r2=1150433&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 Sun
Jul 24 16:45:06 2011
@@ -278,13 +278,12 @@ public class Complex implements FieldEle
         if (isNaN || Double.isNaN(divisor)) {
             return NaN;
         }
-        if (divisor == 0.0) {
+        if (divisor == 0d) {
             return NaN;
         }
-        if (Double.isInfinite(divisor) && !isInfinite()) {
-            return ZERO;
+        if (Double.isInfinite(divisor)) {
+            return !isInfinite() ? ZERO : NaN;     
         }
-
         return createComplex(real / divisor,
                              imaginary  / divisor);
     }

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=1150433&r1=1150432&r2=1150433&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
Sun Jul 24 16:45:06 2011
@@ -274,11 +274,20 @@ public class ComplexTest {
         Complex x = new Complex(1,1);
         double yDouble = Double.POSITIVE_INFINITY;
         Complex yComplex = new Complex(yDouble);
-        Assert.assertEquals(x.divide(yComplex), x.divide(yDouble));
+        TestUtils.assertEquals(x.divide(yComplex), x.divide(yDouble), 0);
 
         yDouble = Double.NEGATIVE_INFINITY;
         yComplex = new Complex(yDouble);
-        Assert.assertEquals(x.divide(yComplex), x.divide(yDouble));
+        TestUtils.assertEquals(x.divide(yComplex), x.divide(yDouble), 0);
+        
+        x = new Complex(1, Double.NEGATIVE_INFINITY);
+        TestUtils.assertEquals(x.divide(yComplex), x.divide(yDouble), 0);
+    }
+    
+    @Test
+    public void testScalarDivideZero() {
+        Complex x = new Complex(1,1);
+        TestUtils.assertEquals(x.divide(Complex.ZERO), x.divide(0), 0);
     }
 
     @Test



Mime
View raw message