ComplexMathUtils { public static ComplexNumber multiply(final ComplexNumber z1, final ComplexNumber z2) { ArgumentChecker.notNull(z1, "z1"); ArgumentChecker.notNull(z2, "z2"); final double a = z1.getReal(); final double b = z1.getImaginary(); final double c = z2.getReal(); final double d = z2.getImaginary(); return new ComplexNumber(a * c - b * d, a * d + b * c); }  static ComplexNumber add(final ComplexNumber z1, final ComplexNumber z2); static ComplexNumber add(final ComplexNumber... z); static ComplexNumber add(final ComplexNumber z, final double x); static ComplexNumber add(final double x, final ComplexNumber z); static double arg(final ComplexNumber z); static ComplexNumber conjugate(final ComplexNumber z); static ComplexNumber divide(final ComplexNumber z1, final ComplexNumber z2); static ComplexNumber divide(final ComplexNumber z, final double x); static ComplexNumber divide(final double x, final ComplexNumber z); static ComplexNumber exp(final ComplexNumber z); static ComplexNumber inverse(final ComplexNumber z); static ComplexNumber log(final ComplexNumber z); static double mod(final ComplexNumber z); static ComplexNumber square(final ComplexNumber z); static ComplexNumber multiply(final ComplexNumber z1, final ComplexNumber z2); static ComplexNumber multiply(final ComplexNumber... z); static ComplexNumber multiply(final double x, final ComplexNumber... z); static ComplexNumber multiply(final ComplexNumber z, final double x); static ComplexNumber multiply(final double x, final ComplexNumber z); static ComplexNumber pow(final ComplexNumber z1, final ComplexNumber z2); static ComplexNumber pow(final ComplexNumber z, final double x); static ComplexNumber pow(final double x, final ComplexNumber z); static ComplexNumber sqrt(final ComplexNumber z); static ComplexNumber subtract(final ComplexNumber z1, final ComplexNumber z2); static ComplexNumber subtract(final ComplexNumber z, final double x); static ComplexNumber subtract(final double x, final ComplexNumber z);  }
@Test public void testMultiplyMany() { ComplexNumber a = multiply(Z1, multiply(Z2, Z1)); ComplexNumber b = multiply(Z1, Z2, Z1); assertComplexEquals(a, b); double x = 3.142; ComplexNumber c = multiply(a, x); ComplexNumber d = multiply(x, Z1, Z1, Z2); assertComplexEquals(c, d); }