Calculates absolute value of a complex number a
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=double) | :: | ar | Real part of |
|||
real(kind=double) | :: | ai | Imaginary part of |
Absolute value of a
function comabs(ar,ai)
!+ Calculates absolute value of a complex number `a`
real(double) :: ar
!+ Real part of `a`
real(double) :: ai
!+ Imaginary part of `a`
real(double) :: comabs
!+ Absolute value of `a`
if (ar == ZERO.and.ai == ZERO) then
Comabs = ZERO
return
endif
ar = DABS(ar)
ai = DABS(ai)
if (ai > ar) then !Switch ai and ar
call RSWAP(ai, ar)
endif
if (ai == ZERO) then
Comabs = ar
else
Comabs = ar * DSQRT(ONE + ai / ar * ai / ar)
endif
end function comabs