Complex implements FieldElement<Complex>, Serializable { public double abs() { if (isNaN) { return Double.NaN; } if (isInfinite()) { return Double.POSITIVE_INFINITY; } if (FastMath.abs(real) < FastMath.abs(imaginary)) { if (imaginary == 0.0) { return FastMath.abs(real); } double q = real / imaginary; return FastMath.abs(imaginary) * FastMath.sqrt(1 + q * q); } else { if (real == 0.0) { return FastMath.abs(imaginary); } double q = imaginary / real; return FastMath.abs(real) * FastMath.sqrt(1 + q * q); } } 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 testAbs() { Complex z = new Complex(3.0, 4.0); Assert.assertEquals(5.0, z.abs(), 1.0e-5); }
@Test public void testAbsInfinite() { Complex z = new Complex(inf, 0); Assert.assertEquals(inf, z.abs(), 0); z = new Complex(0, neginf); Assert.assertEquals(inf, z.abs(), 0); z = new Complex(inf, neginf); Assert.assertEquals(inf, z.abs(), 0); }