This function evaluates the factorial of the argument.
FAC — Function
value. (Output)
See Comments.
N — Argument for which the factorial is desired. (Input)
Generic: FAC (N)
Specific: The specific interface names are S_FAC and D_FAC.
Single: FAC (N)
Double: The double precision function name is DFAC.
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 nne−n overflows.
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.
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
FAC(6) = 720.00
PHONE: 713.784.3131 FAX:713.781.9260 |