Fortran Intrinsic Functions


Fortran provides many commonly used functions, called intrinsic functions. To use a Fortran function, one needs to understand the following items: For example, function SQRT() accepts a REAL argument whose value must be non-negative and computes and returns the square root of the argument. Therefore, SQRT(25.0) returns the square root of 25.0 and SQRT(-1.0) would cause an error since the argument is negative.

Functions in an Expression:

An Example:

The example below has three initialized variables A, B and C. The result is computed and saved into uninitialized variable R.

REAL     ::  A = 1.0, B = -5.0, C = 6.0
REAL     ::  R

R = (-B + SQRT(B*B - 4.0*A*C))/(2.0*A)
The following uses brackets to indicated the order of evaluation:
(-B + SQRT(B*B - 4.0*A*C))/(2.0*A)
     --> ([-B] + SQRT(B*B - 4.0*A*C))/(2.0*A)
     --> (5.0 + SQRT(B*B - 4.0*A*C))/(2.0*A)
     --> (5.0 + SQRT([B*B] - 4.0*A*C))/(2.0*A)
     --> (5.0 + SQRT(25.0 - 4.0*A*C))/(2.0*A)
     --> (5.0 + SQRT(25.0 - [4.0*A]*C))/(2.0*A)
     --> (5.0 + SQRT(25.0 - 4.0*C))/(2.0*A)
     --> (5.0 + SQRT(25.0 - [4.0*C))/(2.0*A)
     --> (5.0 + SQRT(25.0 - 24.0))/(2.0*A)
     --> (5.0 SQRT([25.0 - 24.0]))/(2.0*A)
     --> (5.0 + SQRT(1.0))/(2.0*A)
     --> (5.0 + 1.0)/(2.0*A)
     --> ([5.0 + 1.0])/(2.0*A)
     --> 6.0/(2.0*A)
     --> 6.0/([2.0*A])
     --> 6.0/2.0
     --> 3.0
Therefore, R receives 3.0.