BigComplexMath { public static BigComplex sqrt(BigComplex x, MathContext mathContext) { MathContext mc = new MathContext(mathContext.getPrecision() + 4, mathContext.getRoundingMode()); BigDecimal magnitude = x.abs(mc); BigComplex a = x.add(magnitude, mc); return a.divide(a.abs(mc), mc).multiply(BigDecimalMath.sqrt(magnitude, mc), mc).round(mathContext); }  static BigComplex reciprocal(BigComplex x, MathContext mathContext); static BigComplex conjugate(BigComplex x); static BigDecimal abs(BigComplex x, MathContext mathContext); static BigDecimal absSquare(BigComplex x, MathContext mathContext); static BigDecimal angle(BigComplex x, MathContext mathContext); static BigComplex factorial(BigComplex x, MathContext mathContext); static BigComplex gamma(BigComplex x, MathContext mathContext); static BigComplex exp(BigComplex x, MathContext mathContext); static BigComplex sin(BigComplex x, MathContext mathContext); static BigComplex cos(BigComplex x, MathContext mathContext); static BigComplex tan(BigComplex x, MathContext mathContext); static BigComplex atan(BigComplex x, MathContext mathContext); static BigComplex acot(BigComplex x, MathContext mathContext); static BigComplex asin(BigComplex x, MathContext mathContext); static BigComplex acos(BigComplex x, MathContext mathContext); static BigComplex sqrt(BigComplex x, MathContext mathContext); static BigComplex log(BigComplex x, MathContext mathContext); static BigComplex pow(BigComplex x, long y, MathContext mathContext); static BigComplex pow(BigComplex x, BigDecimal y, MathContext mathContext); static BigComplex pow(BigComplex x, BigComplex y, MathContext mathContext); static BigComplex root(BigComplex x, BigDecimal n, MathContext mathContext); static BigComplex root(BigComplex x, BigComplex n, MathContext mathContext);  }
@Test public void testSqrt() { assertPrecisionCalculation( BigComplex.valueOf(new BigDecimal("1.2720196495140689642524224617374914917156080418400962486"), new BigDecimal("0.78615137775742328606955858584295892952312205783772323766")).round(MC), (mc) -> BigComplexMath.sqrt(BigComplex.valueOf(1, 2), mc), 5); }