Compute the complex square root of a complex number without destructive overflow or underflow.
Finds sqrt(A**2+B**2)
without overflow or destructive underflow
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(in) | :: | a | |||
real(kind=wp), | intent(in) | :: | b |
pure real(wp) function pythag(a, b) implicit none real(wp), intent(in) :: a, b real(wp) :: p, q, r, s, t p = max(abs(a), abs(b)) q = min(abs(a), abs(b)) if (q /= 0.0_wp) then do r = (q/p)**2 t = 4.0_wp + r if (t == 4.0_wp) exit s = r/t p = p + 2.0_wp*p*s q = q*s end do end if pythag = p end function pythag