Fortran 77 Language Reference | ![]() ![]() ![]() ![]() ![]() |
Intrinsic Functions
This chapter tabulates and explains the set of intrinsic functions that are part of Sun WorkShop FORTRAN 77. (For information about Fortran library routines, see the Fortran Library Reference.)
Intrinsic functions that are Sun extensions of the ANSI FORTRAN 77 standard are marked with
.
Intrinsic functions have generic and specific names when they accept arguments of more than one data type. In general, the generic name returns a value with the same data type as its argument. However, there are exceptions such as the type conversion functions (TABLE 6-2) and the inquiry functions (TABLE 6-7). The function may also be called by one of its specific names to handle a specific argument data type.
With functions that work on more than one data item (e.g.
sign(a1,a2)
), all the data arguments must be the same type.In the following tables, the FORTRAN 77 intrinsic functions are listed by:
- Intrinsic Function -description of what the function does
- Definition - a mathematical definition
- No. of Args. - number of arguments the function accepts
- Generic Name - the function's generic name
- Specific Names - the function's specific names
- Argument Type - data type associated with each specific name
- Function Type - data type returned for specific argument data type
Note Compiler options-dbl
,-i2
,-r8
, and-xtypemap
change the default sizes of variables and have an effect on intrinsic references. See Remarks, and the discussion of default sizes and alignment in Size and Alignment of Data Types.
Arithmetic and Mathematical Functions
This section details arithmetic, type conversion, trigonometric, and other functions. "a" stands for a function's single argument, "a1" and "a2" for the first and second arguments of a two argument function, and "ar" and "ai" for the real and imaginary parts of a function's complex argument.
Note that
REAL*16
andCOMPLEX*32
areSPARC
only.Arithmetic
Type Conversion
On an ASCII platform, including Sun systems:
ACHAR
is a nonstandard synonym forCHAR
IACHAR
is a nonstandard synonym forICHAR
On a non-ASCII platform,
ACHAR
andIACHAR
were intended to provide a way to deal directly with ASCII.Trigonometric Functions
Other Mathematical Functions
- The error function: 2/sqrt(pi) x integral from 0 to a of exp(-t*t) dt
Character Functions
TABLE 6-5 Character Functions Conversion
See Note (5).Conversion to character
Conversion to integer
See also:
TABLE 6-2.1
1CHAR
ACHAR![]()
ICHAR
IACHAR![]()
INTEGER
CHARACTERCHARACTER
INTEGERIndex of a substring Location of substring a2 in string a1
See Note (10).2 INDEX
CHARACTER
INTEGER
Length Length of character entity
See Note (11).1 LEN
CHARACTER
INTEGER
Lexically greater than or equal a1 a2
See Note (12).2 LGE
CHARACTER
LOGICAL
Lexically greater than a1 > a2
See Note (12).2 LGT
CHARACTER
LOGICAL
Lexically less than or equal a1 a2
See Note (12).2 LLE
CHARACTER
LOGICAL
Lexically less than a1 < a2
See Note (12).2 LLT
CHARACTER
LOGICAL
On an ASCII platform (including Sun systems):
ACHAR
is a nonstandard synonym forCHAR
IACHAR
is a nonstandard synonym forICHAR
On a non-ASCII platform,
ACHAR
andIACHAR
were intended to provide a way to deal directly with ASCII.Miscellaneous Functions
Other miscellaneous functions include bitwise functions, environmental inquiry functions, and memory allocation and deallocation functions.
Bit Manipulation
![]()
None of these functions are part of the FORTRAN 77 Standard.
The above functions are available as intrinsic or extrinsic functions. See also the discussion of the library bit manipulation routines in the Fortran Library Reference manual.
Environmental Inquiry Functions
![]()
None of these functions are part of the FORTRAN 77 Standard.
Memory
![]()
None of these functions are part of the FORTRAN 77 Standard.
Although
malloc
(3F) andfree
(3F) are not, strictly speaking, intrinsics, they are listed here and in the Fortran Library Reference. Additional non-standard intrinsics, such asisetjmp
(3F),longjmp
(3F), anddate_and_time
(3F), are also described in the Fortran Library Reference and by their man pages.Remarks
The following remarks apply to all of the intrinsic function tables in this chapter.
- The abbreviation
DOUBLE
stands forDOUBLE PRECISION
.- An intrinsic that takes
INTEGER
arguments acceptsINTEGER*2
,INTEGER*4
, orINTEGER*8
.INTEGER
intrinsics that takeINTEGER
arguments return values ofINTEGER
type determined as follows - note that options-i2
,-dbl
, and-xtypemap
may alter the default sizes of actual arguments:
mod sign dim max min and iand or ior xor ieor
-- size of the value returned is the largest of the sizes of the arguments.abs ishft lshift rshift lrshft ibset btest ivclr ishftc ibits
-- size of the value returned is the size of the first argument.int epbase epprec
-- size of the value returned is the size of defaultINTEGER
.ephuge
-- size of the value returned is the size of the defaultINTEGER
, or the size of the argument, whichever is largest.- Options that change the default data sizes (see Size and Alignment of Data Types ) also change the way some intrinsics are used. For example, with
-dbl
in effect, a call toZCOS
with aDOUBLE COMPLEX
argument will automatically become a call toCQCOS
because the argument has been promoted toCOMPLEX*32
. The following functions have this capability:
aimag alog amod cabs ccbrt ccos cdabs cdcbrt cdcos cdexp cdlog cdsin cdsqrt cexp clog csin csqrt dabs dacos dacosd dasin dasind datan datand dcbrt dconjg dcos dcosd dcosh ddim derf derfc dexp dimag dint dlog dmod dnint dprod dsign dsin dsind dsinh dsqrt dtan dtand dtanh idnint iidnnt jidnnt zabs zcbrt zcos zexp zlog zsin zsqrt
- The following functions permit arguments of an integer or logical type of any size:
- and iand ieor iiand iieor iior inot ior jiand jieor jior jnot lrshft lshift not or rshift xor
- (SPARC only) An intrinsic that is shown to return a default
REAL
,DOUBLE
PRECISION
,COMPLEX
, orDOUBLE
COMPLEX
value will return the prevailing type depending on certain compilation options. (See Size and Alignment of Data Types.) For example, if compiled with-xtypemap=real:64,double:64
:
- A call to a
REAL
function returnsREAL*8
- A call to a
DOUBLE
PRECISION
function returnsREAL*8
- A call to a
COMPLEX
function returnsCOMPLEX*16
- A call to a
DOUBLE
COMPLEX
function returnsCOMPLEX*16
- Other options that alter the data sizes of default data types are
-r8
and-dbl
, which also promoteDOUBLE
toQUAD
. The-xtypemap=
option provides more flexibility than these older compiler options and is preferred.- A function with a generic name returns a value with the same type as the argument--except for type conversion functions, the nearest integer function, the absolute value of a complex argument, and others. If there is more than one argument, they must all be of the same type.
- If a function name is used as an actual argument, then it must be a specific name.
- If a function name is used as a dummy argument, then it does not identify an intrinsic function in the subprogram, and it has a data type according to the same rules as for variables and arrays.
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.
If
A
is type integer, thenINT(A)
isA
.If
A
is type real or double precision, then:if
|A| < 1
, thenINT(A
) is 0
if|A|
1
, thenINT(A)
is the greatest integer that does not exceed the magnitude ofA
, and whose sign is the same as the sign ofA
. (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 ofA
.If
A
is type real, thenIFIX(A)
is the same asINT(A)
.If
A
is type real, thenREAL(A)
isA
.If
A
is type integer or double precision, thenREAL(A)
is as much precision of the significant part ofA
as a real datum can contain.If
A
is type complex, thenREAL(A)
is the real part ofA
.If
A
is type double complex, thenREAL(A)
is as much precision of the significant part of the real part ofA
as a real datum can contain.If
A
is type double precision, thenDBLE(A)
isA
.If
A
is type integer or real, thenDBLE(A)
is as much precision of the significant part ofA
as a double precision datum can contain.If
A
is type complex, thenDBLE(A)
is as much precision of the significant part of the real part ofA
as a double precision datum can contain.If
A
is typeCOMPLEX*16
, thenDBLE(A)
is the real part ofA
.If
A
is typeREAL*16
, thenQREAL(A)
isA
.If
A
is type integer, real, or double precision, thenQREAL(A)
is as much precision of the significant part ofA
as aREAL*16
datum can contain.If
A
is type complex or double complex, thenQREAL(A)
is as much precision of the significant part of the real part ofA
as aREAL*16
datum can contain.If
A
is typeCOMPLEX*16
orCOMPLEX*32
, thenQREAL(A)
is the real part ofA
.If
A
is type complex, thenCMPLX(A)
isA
.If
A
is type integer, real, or double precision, thenCMPLX(A)
isREAL(A) + 0i
.If
A1
and
A2
are type integer, real, or double precision, thenCMPLX(A1,A2)
isREAL(A1) + REAL(A2)*i
.If
A
is type double complex, thenCMPLX(A)
isREAL( 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, orCOMPLEX*32
.If
A
is typeCOMPLEX
*16, thenDCMPLX(A)
isA
.If
A
is type integer, real, or double precision, thenDCMPLX(A)
isDBLE(A) + 0i
.If
A1
andA2
are type integer, real, or double precision, thenDCMPLX(A1,A2)
isDBLE(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, orCOMPLEX*32
.
ICHAR(A)
is the position ofA
in the collating sequence.The first position is 0, the last is
N-1, 0
ICHAR(A)
N-1
, whereN
is the number of characters in the collating sequence, andA
is of type character of length one.
CHAR
andICHAR
are inverses in the following sense:
ICHAR(CHAR(I)) = I
, for0
I
N-1
CHAR(ICHAR(C)) = C
, for any characterC
capable of representation in the processorA
COMPLEX
value is expressed as an ordered pair of reals,(ar, ai)
, wherear
is the real part, andai
is the imaginary part.All angles are expressed in radians, unless the "Intrinsic Function" column includes the "(degrees)" remark.
The result of a function of type
COMPLEX
is the principal value.If
a
is ofCOMPLEX
type,CBRT
results inCOMPLEX RT1=(A, B)
, where:A
0.0
, and -60 degreesarctan (B/A) < +
60 degrees.Other two possible results can be evaluated as follows:
RT2 = RT1 * (-0.5, square_root (0.75))
RT3 = RT1 * (-0.5, square_root (0.75))
All arguments in an intrinsic function reference must be of the same type.
INDEX(X,Y)
is the place inX
whereY
starts. That is, it is the starting position within character stringX
of the first occurrence of character stringY
.If
Y
does not occur inX
, thenINDEX(X,Y)
is 0.If
LEN(X) < LEN(Y)
, thenINDEX(X,Y)
is 0.
INDEX
returns defaultINTEGER*4
data. If compiling for a 64-bit environment, the compiler will issue a warning if the result overflows theINTEGER*4
data range. To useINDEX
in a 64-bit environment with character strings larger than theINTEGER*4
limit (2 Gbytes), theINDEX
function and the variables receiving the result must be declaredINTEGER*8
.
LEN
returns the declared length of theCHARACTER
argument variable. The actual value of the argument is of no importance.
LEN
returns defaultINTEGER*4
data. If compiling for a 64-bit environment, the compiler will issue a warning if the result overflows theINTEGER*4
data range. To useLEN
in a 64-bit environment with character variables larger than theINTEGER*4
limit (2 Gbytes), theLEN
function and the variables receiving the result must be declaredINTEGER*8
.
LGE( X, Y )
is true ifX=Y
, or ifX
followsY
in the collating sequence; otherwise, it is false.
LGT( X, Y )
is true ifX
followsY
in the collating sequence; otherwise, it is false.
LLE( X, Y )
is true ifX=Y
, or ifX
precedesY
in the collating sequence; otherwise, it is false.
LLT( X, Y )
is true ifX
precedesY
in the collating sequence; otherwise, it is false.If the operands for
LGE
,LGT
,LLE
, andLLT
are of unequal length, the shorter operand is considered as if it were extended on the right with blanks.See VMS Language Extensions for details on other bitwise operations.
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
andRSHIFT
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.
Only the type of the argument is significant.
Epsilon is the least
e
, such that1.0 + e
1.0
.
The
LOC
function returns the address of a variable or of an external procedure. The function callMALLOC(
n)
allocates a block of at least n bytes, and returns the address of that block.
LOC
returns defaultINTEGER*4
in 32-bit environments,INTEGER*8
in 64-bit environments.
MALLOC
is a library function and not an intrinsic. It too returns defaultINTEGER*4
in 32-bit environments,INTEGER*8
in 64-bit environments. However,MALLOC
must be explicitly declaredINTEGER*8
when compiling for 64-bit environments.The value returned by
LOC
orMALLOC
should be stored in variables typedPOINTER
,INTEGER*4
, orINTEGER*8
in 64-bit environments. The argument toFREE
must be the value returned by a previous call toMALLOC
and hence should have data typePOINTER
,INTEGER*4
, orINTEGER*8
.
MALLOC64
always takes anINTEGER*8
argument (size of memory request in bytes) and always returns anINTEGER*8
value. Use this routine rather thanMALLOC
when compiling programs that must run in both 32-bit and 64-bit environments. The receiving variable must be declared eitherPOINTER
orINTEGER*8
.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 defaultINTEGER*4
data. If compiling for a 64-bit environment, the compiler will issue a warning if the result overflows theINTEGER*4
data range. To useSIZEOF
in a 64-bit environment with arrays larger than theINTEGER*4
limit (2 Gbytes), theSIZEOF
function and the variables receiving the result must be declaredINTEGER*8
.
VMS Intrinsic Functions
This section lists VMS FORTRAN intrinsic routines recognized by
f77
. They are, of course, nonstandard.![]()
VMS Double-Precision Complex
VMS Degree-Based Trigonometric
VMS Bit-Manipulation
VMS Multiple Integer Types
The possibility of multiple integer types is not addressed by the FORTRAN Standard.
f77
copes with their existence by treating a specificINTEGER
-to-INTEGER
function name (IABS
, and so forth) as a special sort of generic. The argument type is used to select the appropriate runtime routine name, which is not accessible to the programmer.VMS FORTRAN takes a similar approach, but makes the specific names available.
TABLE 6-12 VMS Integer Functions IIABS
JIABSAbsolute value
Absolute valueINTEGER*2
INTEGER*4INTEGER*2
INTEGER*4IMAX0
JMAX0Maximum 1
Maximum 1INTEGER*2
INTEGER*4INTEGER*2
INTEGER*4IMIN0
JMIN0Minimum 1
Minimum 1INTEGER*2
INTEGER*4INTEGER*2
INTEGER*4IIDIM
JIDIMPositive difference 2
Positive difference 2INTEGER*2
INTEGER*4INTEGER*2
INTEGER*4IMOD
JMODRemainder of a1/a2
Remainder of a1/a2INTEGER*2
INTEGER*4INTEGER*2
INTEGER*4IISIGN
JISIGNTransfer of sign, |a1|* sign(a2)
Transfer of sign, |a1|* sign(a2)INTEGER*2
INTEGER*4INTEGER*2
INTEGER*4
1 There must be at least two arguments. 2 The positive difference is: a1-min(a1,a2))
Functions Coerced to a Particular Type
Some
VMS
FORTRAN
functions coerce to a particularINTEGER
type.
Functions Translated to a Generic Name
In some cases, each VMS-specific name is translated into an
f77
generic name.
Zero Extend
The following zero-extend functions are recognized by
f77
. The first unused high-order bit is set to zero and extended toward the higher-order end to the width indicated in the table
Sun Microsystems, Inc. Copyright information. All rights reserved. Feedback |
Library | Contents | Previous | Next | Index |