Complex implements FieldElement<Complex>, Serializable { public Complex add(Complex addend) throws NullArgumentException { MathUtils.checkNotNull(addend); if (isNaN || addend.isNaN) { return NaN; } return createComplex(real + addend.getReal(), imaginary + addend.getImaginary()); } 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 testAdd() { Complex x = new Complex(3.0, 4.0); Complex y = new Complex(5.0, 6.0); Complex z = x.add(y); Assert.assertEquals(8.0, z.getReal(), 1.0e-5); Assert.assertEquals(10.0, z.getImaginary(), 1.0e-5); }
@Test public void testAddNaN() { Complex x = new Complex(3.0, 4.0); Complex z = x.add(Complex.NaN); Assert.assertSame(Complex.NaN, z); z = new Complex(1, nan); Complex w = x.add(z); Assert.assertSame(Complex.NaN, w); }
@Test public void testScalarAdd() { Complex x = new Complex(3.0, 4.0); double yDouble = 2.0; Complex yComplex = new Complex(yDouble); Assert.assertEquals(x.add(yComplex), x.add(yDouble)); }
@Test public void testScalarAddNaN() { Complex x = new Complex(3.0, 4.0); double yDouble = Double.NaN; Complex yComplex = new Complex(yDouble); Assert.assertEquals(x.add(yComplex), x.add(yDouble)); }
@Test public void testScalarAddInf() { Complex x = new Complex(1, 1); double yDouble = Double.POSITIVE_INFINITY; Complex yComplex = new Complex(yDouble); Assert.assertEquals(x.add(yComplex), x.add(yDouble)); x = new Complex(neginf, 0); Assert.assertEquals(x.add(yComplex), x.add(yDouble)); }