diff --git a/src/main/java/org/apache/commons/math/complex/Complex.java b/src/main/java/org/apache/commons/math/complex/Complex.java index 746c54901..7bc354a28 100644 --- a/src/main/java/org/apache/commons/math/complex/Complex.java +++ b/src/main/java/org/apache/commons/math/complex/Complex.java @@ -177,7 +177,7 @@ public class Complex implements FieldElement, Serializable { *

      *    a + bi          ac + bd + (bc - ad)i
      *    ----------- = -------------------------
-     *    c + di               c2 + d2
+     *    c + di         c2 + d2
      * 
* but uses * @@ -221,17 +221,11 @@ public class Complex implements FieldElement, Serializable { } 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, diff --git a/src/site/xdoc/changes.xml b/src/site/xdoc/changes.xml index 511037a2b..d3937e1b2 100644 --- a/src/site/xdoc/changes.xml +++ b/src/site/xdoc/changes.xml @@ -39,6 +39,9 @@ The type attribute can be add,update,fix,remove. + + Removed dead code from Complex#divide. + Fixed implementation of RandomDataImpl#nextPoisson by implementing an alternative algorithm for large means. diff --git a/src/test/java/org/apache/commons/math/complex/ComplexTest.java b/src/test/java/org/apache/commons/math/complex/ComplexTest.java index cd9b15ec9..e78ada46c 100644 --- a/src/test/java/org/apache/commons/math/complex/ComplexTest.java +++ b/src/test/java/org/apache/commons/math/complex/ComplexTest.java @@ -144,6 +144,19 @@ public class ComplexTest extends TestCase { 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 @@ public class ComplexTest extends TestCase { 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);