comabs Function

public function comabs(ar, ai)

Calculates absolute value of a complex number a

Arguments

Type IntentOptional AttributesName
real(kind=double) :: ar

Real part of a

real(kind=double) :: ai

Imaginary part of a

Return Value real(kind=double)

Absolute value of a


Calls

proc~~comabs~~CallsGraph proc~comabs comabs proc~rswap RSWAP proc~comabs->proc~rswap

Contents

Source Code


Source Code

  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