BigComplex { @Override public String toString() { if (im.signum() >= 0) { return "(" + re + " + " + im + " i)"; } else { return "(" + re + " - " + im.negate() + " i)"; } } private  BigComplex(BigDecimal re, BigDecimal im); BigComplex add(BigComplex value); BigComplex add(BigComplex value, MathContext mathContext); BigComplex add(BigDecimal value, MathContext mathContext); BigComplex add(BigDecimal value); BigComplex add(double value); BigComplex subtract(BigComplex value); BigComplex subtract(BigComplex value, MathContext mathContext); BigComplex subtract(BigDecimal value, MathContext mathContext); BigComplex subtract(BigDecimal value); BigComplex subtract(double value); BigComplex multiply(BigComplex value); BigComplex multiply(BigComplex value, MathContext mathContext); BigComplex multiply(BigDecimal value, MathContext mathContext); BigComplex multiply(BigDecimal value); BigComplex multiply(double value); BigComplex divide(BigComplex value, MathContext mathContext); BigComplex divide(BigDecimal value, MathContext mathContext); BigComplex divide(double value, MathContext mathContext); BigComplex reciprocal(MathContext mathContext); BigComplex conjugate(); BigComplex negate(); BigDecimal abs(MathContext mathContext); BigDecimal angle(MathContext mathContext); BigDecimal absSquare(MathContext mathContext); boolean isReal(); BigComplex re(); BigComplex im(); BigComplex round(MathContext mathContext); @Override int hashCode(); @Override boolean equals(Object obj); boolean strictEquals(Object obj); @Override String toString(); static BigComplex valueOf(BigDecimal real); static BigComplex valueOf(double real); static BigComplex valueOf(double real, double imaginary); static BigComplex valueOf(BigDecimal real, BigDecimal imaginary); static BigComplex valueOfPolar(BigDecimal radius, BigDecimal angle, MathContext mathContext); static BigComplex valueOfPolar(double radius, double angle, MathContext mathContext); static final BigComplex ZERO; static final BigComplex ONE; static final BigComplex I; final BigDecimal re; final BigDecimal im; }
@Test public void testToString() { assertEquals("(1.2 + 3.4 i)", BigComplex.valueOf(1.2, 3.4).toString()); assertEquals("(1.2 - 3.4 i)", BigComplex.valueOf(1.2, -3.4).toString()); assertEquals("(1.2 + 0.0 i)", BigComplex.valueOf(1.2, 0.0).toString()); assertEquals("(0.0 + 3.4 i)", BigComplex.valueOf(0.0, 3.4).toString()); }