diff --git a/src/java/org/apache/commons/math/complex/Complex.java b/src/java/org/apache/commons/math/complex/Complex.java index 16b387332..8b622cb29 100644 --- a/src/java/org/apache/commons/math/complex/Complex.java +++ b/src/java/org/apache/commons/math/complex/Complex.java @@ -255,10 +255,7 @@ public class Complex implements Serializable { if (rhs.isNaN()) { ret = this.isNaN(); } else { - ret = (Double.doubleToRawLongBits(real) == - Double.doubleToRawLongBits(rhs.getReal())) && - (Double.doubleToRawLongBits(imaginary) == - Double.doubleToRawLongBits(rhs.getImaginary())); + ret = (real == rhs.real) && (imaginary == rhs.imaginary); } } catch (ClassCastException ex) { // ignore exception diff --git a/src/site/xdoc/changes.xml b/src/site/xdoc/changes.xml index ee0980f1f..a38c39c21 100644 --- a/src/site/xdoc/changes.xml +++ b/src/site/xdoc/changes.xml @@ -39,6 +39,10 @@ The type attribute can be add,update,fix,remove. + + Changed the Complex.equals() method so that it considers +0 and -0 are equal, + as required by IEEE-754 standard. + Added JAMA-like interfaces for decomposition algorithms. These interfaces decompose a matrix as a product of several other matrices with predefined diff --git a/src/test/org/apache/commons/math/complex/ComplexTest.java b/src/test/org/apache/commons/math/complex/ComplexTest.java index 4ba7a6513..61ff86f52 100644 --- a/src/test/org/apache/commons/math/complex/ComplexTest.java +++ b/src/test/org/apache/commons/math/complex/ComplexTest.java @@ -690,4 +690,10 @@ public class ComplexTest extends TestCase { public void testTanhCritical() { TestUtils.assertSame(nanInf, new Complex(0, pi/2).tanh()); } + + /** test issue MATH-221 */ + public void testMath221() { + assertEquals(new Complex(0,-1), new Complex(0,1).multiply(new Complex(-1,0))); + } + }