csqrt method

complex csqrt(
  1. complex z
)

Computes the complex square root of z.

Implementation

complex csqrt(complex z) {
  double r = cabs(z);
  double sign = z.imag < 0 ? -1.0 : 1.0;
  return complex(
    math.sqrt((r + z.real) / 2.0),
    sign * math.sqrt((r - z.real) / 2.0)
  );
}