Complex implements Serializable { public static Complex cart(final double re, final double im) { if (re == 0.0) { if (im == 1.0) return Complex.I; if (im == 0.0) return Complex.ZERO; if (im == -1.0) return Complex.NEG_I; } else if (im == 0.0) { if (re == 1.0) return Complex.ONE; if (re == -1.0) return Complex.NEG_ONE; if (re == -2.0) return Complex.NEG_TWO; } return new Complex(re, im); } private  Complex(final double re, final double im); static Complex cart(final double re, final double im); static Complex[] difference(final Complex[] lr, final int lrlength,
	    final Complex[] rr, final int rrlength, final double epsilon); static double distance(Complex l, Complex r); static Complex[] intersection(final int lnroots,
	    final Complex[] lroots, final int rnroots, final Complex[] rroots,
	    final double epsilon); static void lejaOrder(final Complex[] xin); static Complex polar(double r, double theta); static Complex[] roots(final Complex c, final int nRoots); static Complex[] union(final Complex[] lr, final Complex[] rr); static Complex[] union(final Complex[] lr, final int lrlength,
	    final Complex[] rr, final int rrlength); static Complex[] unitRoots(final int nRoots); static Complex cart(final double re); double abs(); double absSquare(); Complex sqrt(); double arg(); Complex conj(); Complex div(final Complex c); Complex div(final double b); boolean equals(final Complex z, final double tolerance); @Override boolean equals(Object obj); double getIm(); double getRe(); @Override int hashCode(); Complex inv(); boolean isInfinity(); boolean isNaN(); Complex minus(final Complex b); Complex minus(final double z); Complex negate(); Complex plus(final Complex b); Complex plus(final double a); Complex times(final Complex b); Complex times(final double z); @Override String toString(); static final Complex I; static final Complex TWO; static final Complex ONE; static final Complex ZERO; static final Complex NEG_ONE; static final Complex NEG_TWO; static final Complex NEG_I; final static double EPS; final static double TWOPI; }
@Test public void testCart() { Assert.assertEquals(54.654, c1.getRe(), 0); Assert.assertEquals(7.321, c1.getIm(), 0); Assert.assertSame(Complex.ZERO, cart(0, 0)); Assert.assertSame(Complex.ONE, cart(1, 0)); Assert.assertSame(Complex.NEG_ONE, cart(-1, 0)); Assert.assertSame(Complex.I, cart(0, 1)); Assert.assertSame(Complex.NEG_I, cart(0, -1)); Assert.assertNotSame(cart(54.654, 7.321), c1); }