Complex implements FieldElement<Complex>, Serializable { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other instanceof Complex){ Complex c = (Complex) other; if (c.isNaN) { return isNaN; } else { return MathUtils.equals(real, c.real) && MathUtils.equals(imaginary, c.imaginary); } } return false; } Complex(double real);  Complex(double real, double imaginary); double abs(); Complex add(Complex addend); Complex add(double addend); Complex conjugate(); Complex divide(Complex divisor); Complex divide(double divisor); Complex reciprocal(); @Override boolean equals(Object other); static boolean equals(Complex x, Complex y, int maxUlps); static boolean equals(Complex x, Complex y); static boolean equals(Complex x, Complex y, double eps); static boolean equalsWithRelativeTolerance(Complex x, Complex y,
                                                      double eps); @Override int hashCode(); double getImaginary(); double getReal(); boolean isNaN(); boolean isInfinite(); Complex multiply(Complex factor); Complex multiply(final int factor); Complex multiply(double factor); Complex negate(); Complex subtract(Complex subtrahend); Complex subtract(double subtrahend); Complex acos(); Complex asin(); Complex atan(); Complex cos(); Complex cosh(); Complex exp(); Complex log(); Complex pow(Complex x); Complex pow(double x); Complex sin(); Complex sinh(); Complex sqrt(); Complex sqrt1z(); Complex tan(); Complex tanh(); double getArgument(); List<Complex> nthRoot(int n); static Complex valueOf(double realPart,
                                  double imaginaryPart); static Complex valueOf(double realPart); ComplexField getField(); @Override String toString(); static final Complex I; static final Complex NaN; static final Complex INF; static final Complex ONE; static final Complex ZERO; }
@Test public void testEqualsNull() { Complex x = new Complex(3.0, 4.0); Assert.assertFalse(x.equals(null)); }
@Test(expected=NullPointerException.class) public void testFloatingPointEqualsPrecondition1() { Complex.equals(new Complex(3.0, 4.0), null, 3); }
@Test(expected=NullPointerException.class) public void testFloatingPointEqualsPrecondition2() { Complex.equals(null, new Complex(3.0, 4.0), 3); }
@Test public void testEqualsClass() { Complex x = new Complex(3.0, 4.0); Assert.assertFalse(x.equals(this)); }
@Test public void testEqualsSame() { Complex x = new Complex(3.0, 4.0); Assert.assertTrue(x.equals(x)); }
@Test public void testFloatingPointEquals() { double re = -3.21; double im = 456789e10; final Complex x = new Complex(re, im); Complex y = new Complex(re, im); Assert.assertTrue(x.equals(y)); Assert.assertTrue(Complex.equals(x, y)); final int maxUlps = 5; for (int i = 0; i < maxUlps; i++) { re = FastMath.nextUp(re); im = FastMath.nextUp(im); } y = new Complex(re, im); Assert.assertTrue(Complex.equals(x, y, maxUlps)); re = FastMath.nextUp(re); im = FastMath.nextUp(im); y = new Complex(re, im); Assert.assertFalse(Complex.equals(x, y, maxUlps)); }
@Test public void testFloatingPointEqualsNaN() { Complex c = new Complex(Double.NaN, 1); Assert.assertFalse(Complex.equals(c, c)); c = new Complex(1, Double.NaN); Assert.assertFalse(Complex.equals(c, c)); }
@Test public void testFloatingPointEqualsWithAllowedDelta() { final double re = 153.0000; final double im = 152.9375; final double tol1 = 0.0625; final Complex x = new Complex(re, im); final Complex y = new Complex(re + tol1, im + tol1); Assert.assertTrue(Complex.equals(x, y, tol1)); final double tol2 = 0.0624; Assert.assertFalse(Complex.equals(x, y, tol2)); }
@Test public void testEqualsTrue() { Complex x = new Complex(3.0, 4.0); Complex y = new Complex(3.0, 4.0); Assert.assertTrue(x.equals(y)); }
@Test public void testEqualsRealDifference() { Complex x = new Complex(0.0, 0.0); Complex y = new Complex(0.0 + Double.MIN_VALUE, 0.0); Assert.assertFalse(x.equals(y)); }
@Test public void testEqualsImaginaryDifference() { Complex x = new Complex(0.0, 0.0); Complex y = new Complex(0.0, 0.0 + Double.MIN_VALUE); Assert.assertFalse(x.equals(y)); }
@Test public void testEqualsNaN() { Complex realNaN = new Complex(Double.NaN, 0.0); Complex imaginaryNaN = new Complex(0.0, Double.NaN); Complex complexNaN = Complex.NaN; Assert.assertTrue(realNaN.equals(imaginaryNaN)); Assert.assertTrue(imaginaryNaN.equals(complexNaN)); Assert.assertTrue(realNaN.equals(complexNaN)); }