FAC
This function evaluates the factorial of the argument.
Function Return Value
FAC — Function value. (Output)
See Comments.
Required Arguments
N — Argument for which the factorial is desired. (Input)
FORTRAN 90 Interface
Generic: FAC (N)
Specific: The specific interface names are S_FAC and D_FAC.
FORTRAN 77 Interface
Single: FAC (N)
Double: The double precision function name is DFAC.
Description
The factorial is computed using the relation n! = Γ(n + 1). The function Γ(x) is defined in GAMMA. The argument n must be greater than or equal to zero, and it must not be so large that n! overflows. Approximately, n! overflows when nnen overflows.
Comments
If the generic version of this function is used, the immediate result must be stored in a variable before use in an expression. For example:
X = FAC(6)
Y = SQRT(X)
must be used rather than
Y = SQRT(FAC(6)).
If this is too much of a restriction on the programmer, then the specific name can be used without this restriction.
To evaluate the factorial for nonintegral values of the argument, the gamma function should be used. For large values of the argument, the log gamma function should be used.
Example
In this example, 6! is computed and printed.
 
USE FAC_INT
USE UMACH_INT
 
IMPLICIT NONE
! Declare variables
INTEGER N, NOUT
REAL VALUE
! Compute
N = 6
VALUE = FAC(N)
! Print the results
CALL UMACH (2, NOUT)
WRITE (NOUT,99999) N, VALUE
99999 FORMAT (' FAC(', I1, ') = ', F6.2)
END
Output
 
FAC(6) = 720.00