LF Fortran 95

LOG Function

Description

The LOG function returns the natural logarithm of a real or complex argument.

Syntax

LOG (x)

Arguments

x is an INTENT(IN) scalar or array of type REAL or COMPLEX.

If x is REAL, it must be greater than zero.

If x is COMPLEX, it must not be equal to zero.

Result

The result is of the same type and kind as x.

If x is REAL, its value is equal to a REAL representation of log ex.

If x is COMPLEX, its value is equal to the principal value with imaginary part Ω in the range -Π < Ω ≤ Π.

If x is REAL and equal to zero, a floating divide exception occurs, and unless trapped, the value -Inf (negative infinity) is returned.

If x is REAL and less than zero, an invalid operation exception occurs, and unless trapped, the value -NaN (not a number) is returned.

If x is COMPLEX with both the real and imaginary parts equal to zero, a runtime error occurs and execution is terminated.

Example

real :: x.1.,xa(2)=(/.5,1.5/),pi=3.141592654 real :: re,im complex :: q=(-1.,1.) write(*,*) log(x) ! writes 0.0 write(*,*) log(xa) ! writes -.69314718 .40546509 write(*,*) log(q) ! writes (.34657359, 2.3561945) re=log((sqrt(real(q)**2+aimag(q)**2))) ! real part of log(q) im=-atan2(real(q),aimag(q))+pi/2. ! imag part of log(q) write(*,*) re,im write(*,*) log(0.) ! writes -Inf or error occurs write(*,*) log(-1.) ! writes -NaN or error occurs