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 dd0b00a5b..ac31e4b1b 100644 --- a/src/main/java/org/apache/commons/math/complex/Complex.java +++ b/src/main/java/org/apache/commons/math/complex/Complex.java @@ -78,8 +78,6 @@ public class Complex implements FieldElement, Serializable { private final transient boolean isNaN; /** Record whether this complex number is infinite. */ private final transient boolean isInfinite; - /** Record whether this complex number is zero. */ - private final transient boolean isZero; /** * Create a complex number given only the real part. @@ -103,7 +101,6 @@ public class Complex implements FieldElement, Serializable { isNaN = Double.isNaN(real) || Double.isNaN(imaginary); isInfinite = !isNaN && (Double.isInfinite(real) || Double.isInfinite(imaginary)); - isZero = real == 0 && imaginary == 0; } /** @@ -225,10 +222,7 @@ public class Complex implements FieldElement, Serializable { *
  • If either {@code this} or {@code divisor} has a {@code NaN} value * in either part, {@link #NaN} is returned. *
  • - *
  • If {@code this} and {@code divisor} are both {@link #ZERO}, - * {@link #NaN} is returned. - *
  • - *
  • If {@code divisor} equals {@link #ZERO}, {@link #INF} is returned. + *
  • If {@code divisor} equals {@link #ZERO}, {@link #NaN} is returned. *
  • *
  • If {@code this} and {@code divisor} are both infinite, * {@link #NaN} is returned. @@ -255,8 +249,9 @@ public class Complex implements FieldElement, Serializable { return NaN; } - if (divisor.isZero) { - // return isZero ? NaN : INF; // See MATH-657 + final double c = divisor.getReal(); + final double d = divisor.getImaginary(); + if (c == 0.0 && d == 0.0) { return NaN; } @@ -264,9 +259,6 @@ public class Complex implements FieldElement, Serializable { return ZERO; } - final double c = divisor.getReal(); - final double d = divisor.getImaginary(); - if (FastMath.abs(c) < FastMath.abs(d)) { double q = c / d; double denominator = c * q + d; @@ -293,7 +285,6 @@ public class Complex implements FieldElement, Serializable { return NaN; } if (divisor == 0d) { - // return isZero ? NaN : INF; // See MATH-657 return NaN; } if (Double.isInfinite(divisor)) { 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 71bdd1e1f..4bc85b8f7 100644 --- a/src/test/java/org/apache/commons/math/complex/ComplexTest.java +++ b/src/test/java/org/apache/commons/math/complex/ComplexTest.java @@ -229,14 +229,6 @@ public class ComplexTest { public void testDivideZero() { Complex x = new Complex(3.0, 4.0); Complex z = x.divide(Complex.ZERO); - // Assert.assertEquals(z, Complex.INF); // See MATH-657 - Assert.assertEquals(z, Complex.NaN); - } - - @Test - public void testDivideZeroZero() { - Complex x = new Complex(0.0, 0.0); - Complex z = x.divide(Complex.ZERO); Assert.assertEquals(z, Complex.NaN); } @@ -357,13 +349,13 @@ public class ComplexTest { @Test public void testScalarMultiplyInf() { - Complex x = new Complex(1, 1); + Complex x = new Complex(1,1); double yDouble = Double.POSITIVE_INFINITY; Complex yComplex = new Complex(yDouble); Assert.assertEquals(x.multiply(yComplex), x.multiply(yDouble)); yDouble = Double.NEGATIVE_INFINITY; - yComplex = new Complex(yDouble); + yComplex = new Complex(yDouble); Assert.assertEquals(x.multiply(yComplex), x.multiply(yDouble)); } @@ -572,14 +564,10 @@ public class ComplexTest { TestUtils.assertSame(Complex.NaN, negInfNegInf.atan()); } - @Test - public void testAtanI() { - Assert.assertTrue(Complex.I.atan().isNaN()); - } - @Test public void testAtanNaN() { Assert.assertTrue(Complex.NaN.atan().isNaN()); + Assert.assertTrue(Complex.I.atan().isNaN()); } @Test