FORTRAN 77 Language Reference

Notes on Functions

Tables and notes 1 through 12 are based on the "Table of Intrinsic Functions," from ANSI X3.9-1978 Programming Language FORTRAN, with the FORTRAN extensions added.

(1) INT

If A is type integer, then INT(A) is A.

If A is type real or double precision, then:

if |A| < 1, then INT(A) is 0 if |A| 1, then INT(A) is the greatest integer that does not exceed the magnitude of A, and whose sign is the same as the sign of A. (Such a mathematical integer value may be too large to fit in the computer integer type.)

If A is type complex or double complex, then apply the above rule to the real part of A.

If A is type real, then IFIX(A) is the same as INT(A).

(2) REAL

If A is type real, then REAL(A) is A.

If A is type integer or double precision, then REAL(A) is as much precision of the significant part of A as a real datum can contain.

If A is type complex, then REAL(A) is the real part of A.

If A is type double complex, then REAL(A) is as much precision of the significant part of the real part of A as a real datum can contain.

(3) DBLE

If A is type double precision, then DBLE(A) is A.

If A is type integer or real, then DBLE(A) is as much precision of the significant part of A as a double precision datum can contain.

If A is type complex, then DBLE(A) is as much precision of the significant part of the real part of A as a double precision datum can contain.

If A is type COMPLEX*16, then DBLE(A) is the real part of A.

(3') QREAL

If A is type REAL*16, then QREAL(A) is A.

If A is type integer, real, or double precision, then QREAL(A) is as much precision of the significant part of A as a REAL*16 datum can contain.

If A is type complex or double complex, then QREAL(A) is as much precision of the significant part of the real part of A as a REAL*16 datum can contain.

If A is type COMPLEX*16 or COMPLEX*32, then QREAL(A) is the real part of A.

(4) CMPLX

If A is type complex, then CMPLX(A) is A.

If A is type integer, real, or double precision, then CMPLX(A) is REAL(A) + 0i.

If A1 and A2 are type integer, real, or double precision, then CMPLX(A1,A2) is REAL(A1) + REAL(A2)*i.

If A is type double complex, then CMPLX(A) is REAL( DBLE(A) ) + i*REAL( DIMAG(A) ).

If CMPLX has two arguments, then they must be of the same type, and they may be one of integer, real, or double precision.

If CMPLX has one argument, then it may be one of integer, real, double precision, complex, COMPLEX*16, or COMPLEX*32.

(4') DCMPLX

If A is type COMPLEX*16, then DCMPLX(A) is A.

If A is type integer, real, or double precision, then DCMPLX(A) is DBLE(A) + 0i.

If A1 and A2 are type integer, real, or double precision, then DCMPLX(A1,A2) is DBLE(A1) + DBLE(A2)*i.

If DCMPLX has two arguments, then they must be of the same type, and they may be one of integer, real, or double precision.

If DCMPLX has one argument, then it may be one of integer, real, double precision, complex, COMPLEX*16, or COMPLEX*32.

(5) ICHAR

ICHAR(A) is the position of A in the collating sequence.

The first position is 0, the last is N-1, 0£ICHAR(A)£N-1, where N is the number of characters in the collating sequence, and A is of type character of length one.

CHAR and ICHAR are inverses in the following sense:

(6) COMPLEX

A COMPLEX value is expressed as an ordered pair of reals, (ar, ai), where ar is the real part, and ai is the imaginary part.

(7) Radians

All angles are expressed in radians, unless the "Intrinsic Function" column includes the "(degrees)" remark.

(8) COMPLEX Function

The result of a function of type COMPLEX is the principal value.

(8') CBRT

If a is of COMPLEX type, CBRT results in COMPLEX RT1=(A, B), where: A>= 0.0, and -60 degrees <= arctan (B/A) < + 60 degrees.

Other two possible results can be evaluated as follows:

(9) Argument types

All arguments in an intrinsic function reference must be of the same type.

(10) INDEX

INDEX(X,Y) is the place in X where Y starts. That is, it is the starting position within character string X of the first occurrence of character string Y.

If Y does not occur in X, then INDEX(X,Y) is 0.

If LEN(X) < LEN(Y), then INDEX(X,Y) is 0.

INDEX returns default INTEGER*4 data. If compiling for a 64-bit environment, the compiler will issue a warning if the result overflows the INTEGER*4 data range. To use INDEX in a 64-bit environment with character strings larger than the INTEGER*4 limit (2 Gbytes), the INDEX function and the variables receiving the result must be declared INTEGER*8.

(11) LEN

LEN returns the declared length of the CHARACTER argument variable. The actual value of the argument is of no importance.

LEN returns default INTEGER*4 data. If compiling for a 64-bit environment, the compiler will issue a warning if the result overflows the INTEGER*4 data range. To use LEN in a 64-bit environment with character variables larger than the INTEGER*4 limit (2 Gbytes), the LEN function and the variables receiving the result must be declared INTEGER*8.

(12) Lexical Compare

LGE( X, Y ) is true if X=Y, or if X follows Y in the collating sequence; otherwise, it is false.

LGT( X, Y ) is true if X follows Y in the collating sequence; otherwise, it is false.

LLE( X, Y ) is true if X=Y, or if X precedes Y in the collating sequence; otherwise, it is false.

LLT( X, Y ) is true if X precedes Y in the collating sequence; otherwise, it is false.

If the operands for LGE, LGT, LLE, and LLT are of unequal length, the shorter operand is considered as if it were extended on the right with blanks.

(13) Bit Functions

See Appendix D, VMS Language Extensions for details on other bitwise operations.

(14) Shift

LSHIFT shifts a1 logically left by a2 bits (inline code).

LRSHFT shifts a1 logically right by a2 bits (inline code).

RSHIFT shifts a1 arithmetically right by a2 bits.

ISHFT shifts a1 logically left if a2 > 0 and right if a2 < 0.

The LSHIFT and RSHIFT functions are the FORTRAN analogs of the C << and >> operators. As in C, the semantics depend on the hardware.

The behavior of the shift functions with an out of range shift count is hardware dependent and generally unpredictable. In this release, shift counts larger than 31 result in hardware dependent behavior.

(15) Environmental inquiries

Only the type of the argument is significant.

(16) Epsilon

Epsilon is the least e, such that 1.0 + e 1.0.

(17) LOC, MALLOC, and FREE

The LOC function returns the address of a variable or of an external procedure. The function call MALLOC( n ) allocates a block of at least n bytes, and returns the address of that block.

LOC returns default INTEGER*4 in 32-bit environments, INTEGER*8 in 64-bit environments.

MALLOC is a library function and not an intrinsic. It too returns default INTEGER*4 in 32-bit environments, INTEGER*8 in 64-bit environments. However, MALLOC must be explicitly declared INTEGER*8 when compiling for 64-bit environments.

The value returned by LOC or MALLOC should be stored in variables typed POINTER, INTEGER*4, or INTEGER*8 in 64-bit environments. The argument to FREE must be the value returned by a previous call to MALLOC and hence should have data type POINTER, INTEGER*4, or INTEGER*8.

MALLOC64 always takes an INTEGER*8 argument (size of memory request in bytes) and always returns an INTEGER*8 value. Use this routine rather than MALLOC when compiling programs that must run in both 32-bit and 64-bit environments. The receiving variable must be declared either POINTER or INTEGER*8.

(18) SIZEOF

The SIZEOF intrinsic cannot be applied to arrays of an assumed size, characters of a length that is passed, or subroutine calls or names. SIZEOF returns default INTEGER*4 data. If compiling for a 64-bit environment, the compiler will issue a warning if the result overflows the INTEGER*4 data range. To use SIZEOF in a 64-bit environment with arrays larger than the INTEGER*4 limit (2 Gbytes), the SIZEOF function and the variables receiving the result must be declared INTEGER*8.