Compute the complex square root of a complex number.
(YR,YI) = complex sqrt(XR,XI)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(in) | :: | xr | |||
real(kind=wp), | intent(in) | :: | xi | |||
real(kind=wp), | intent(out) | :: | yr | |||
real(kind=wp), | intent(out) | :: | yi |
pure subroutine csroot(xr, xi, yr, yi) implicit none real(wp), intent(in) :: xr, xi real(wp), intent(out) :: yr, yi real(wp) :: s, tr, ti ! branch chosen so that yr >= 0.0 and sign(yi) == sign(xi) tr = xr ti = xi s = sqrt(0.5_wp*(pythag(tr, ti) + abs(tr))) if (tr >= 0.0_wp) yr = s if (ti < 0.0_wp) s = -s if (tr <= 0.0_wp) yi = s if (tr < 0.0_wp) yr = 0.5_wp*(ti/yi) if (tr > 0.0_wp) yi = 0.5_wp*(ti/yr) end subroutine csroot