FORTRAN provides a variety of intrinsic functions which may be used in any
program unit. They are subject neither to type declarations nor
IMPLICIT statements. Their names are not reserved keywords
but to avoid confusion, it is inadvisable to use these names as arrays,
constants, variables or user-defined external subprograms. If, however, it
is desirable to use the name of an intrinsic function as the name of a
user-defined external subprogram, then the name must be declared in an
EXTERNAL statement in the program unit which invokes it.
If an intrinsic function appears in the actual argument list of an
external subprogram invocation or CALL statement, then it must
be declared in an INTRINSIC statement.
PROGRAM MAIN REAL PI INTRINSIC COS,SIN PARAMETER(PI=3.14159265) WRITE(*,*)'Cosine Function' CALL TABLE(COS,-PI,PI) WRITE(*,*)'Sine Function' CALL TABLE(SIN,-PI,PI) ... STOP 'End of program' END SUBROUTINE TABLE(F,LOWER,UPPER) REAL F,LOWER,UPPER,X ... WRITE(*,*)X,F(X) ... RETURN END
The intrinsic functions COS and SIN are passed to
a user-defined SUBROUTINE called TABLE and so
must be declared as INTRINSIC in the calling program unit
(the main program in this case).
The following table outlines the generic forms of these functions.
C stands for CHARACTER data,
D for DOUBLE PRECISION,
I for INTEGER,
L for LOGICAL,
R for REAL (single precision)
and X for COMPLEX
(single precision). Note that the MAX and
MIN intrinsic functions may take any number of arguments but
the rest take either one or two arguments.
| Function | Argument Type | Return Type | Description |
|---|---|---|---|
| ABS | X | R | modulus of a complex number |
| ABS | DIR | DIR | absolute value of a number |
| ACOS | DR | DR | arccosine of a number |
| AIMAG | X | R | imaginary part of a complex number |
| AINT | DR | DR | truncates fractional part but preserves data type |
| ANINT | DR | DR | rounds to nearest whole number but preserves data type |
| ASIN | DR | DR | arcsine of a number |
| ATAN | DR | DR | arctangent of a number |
| ATAN2 | DR,DR | DR | arctangent of arg1 divided by arg2 resolved into the correct quadrant |
| CHAR | I | C | returns nth character in character code table |
| CMPLX | DIRX | X | converts to the COMPLEX data type |
| CMPLX | DIR,DIR | X | converts to the COMPLEX data type
arg1 + i arg2 |
| CONJG | X | X | complex conjugate of a complex number |
| COS | DRX | DRX | cosine of an angle in radians |
| COSH | DR | DR | hyperbolic cosine |
| DBLE | DIRX | D | converts to the DOUBLE PRECISION data type |
| DIM | DIR,DIR | DIR | if arg1 > arg2, then returns arg1 - arg2; otherwise 0 |
| DPROD | R,R | D | double precision product of two single precision numbers |
| EXP | DRX | DRX | exponential |
| ICHAR | C | I | position of first character in string in the character code table |
| INDEX | C,C | I | searches first string and returns position of second string within it |
| INT | DIRX | I | converts to the INTEGER data type by truncation |
| LEN | C | I | length of character argument |
| LGE | C,C | L | lexical comparison; true if arg1 >= arg2 in ASCII character code |
| LGT | C,C | L | lexical comparison; true if arg1 > arg2 in ASCII character code |
| LLE | C,C | L | lexical comparison; true if arg1 <= arg2 in ASCII character code |
| LLT | C,C | L | lexical comparison; true if arg1 < arg2 in ASCII character code |
| LOG | DRX | DRX | natural logarithm |
| LOG10 | DRX | DRX | common logarithm |
| MAX | DIR,DIR,... | DIR | maximum value of arguments |
| MIN | DIR,DIR,... | DIR | minimum value of arguments |
| MOD | DIR,DIR | DIR,DIR | arg1 modulo arg2 |
| NINT | DR | I | converts to the INTEGER data type by rounding |
| REAL | X | R | real part of a complex number |
| REAL | DIR | R | converts to the REAL data type |
| SIGN | DIR,DIR | DIR | if arg2 < 0, then returns -arg1; else +arg1 |
| SIN | DRX | DRX | sine of an angle in radians |
| SINH | DR | DR | hyperbolic sine |
| SQRT | DRX | DRX | square root |
| TAN | DR | DR | tangent of an angle in radians |
| TANH | DR | DR | hyperbolic tangent |