| 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-xtypemapchange 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*16andCOMPLEX*32areSPARConly.Arithmetic
Type Conversion
On an ASCII platform, including Sun systems:
ACHARis a nonstandard synonym forCHARIACHARis a nonstandard synonym forICHAROn a non-ASCII platform,
ACHARandIACHARwere 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 INDEXCHARACTERINTEGERLength Length of character entity
See Note (11).1 LENCHARACTERINTEGERLexically greater than or equal a1 a2
See Note (12).2 LGECHARACTERLOGICALLexically greater than a1 > a2
See Note (12).2 LGTCHARACTERLOGICALLexically less than or equal a1 a2
See Note (12).2 LLECHARACTERLOGICALLexically less than a1 < a2
See Note (12).2 LLTCHARACTERLOGICAL
On an ASCII platform (including Sun systems):
ACHARis a nonstandard synonym forCHARIACHARis a nonstandard synonym forICHAROn a non-ASCII platform,
ACHARandIACHARwere 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
DOUBLEstands forDOUBLE PRECISION.- An intrinsic that takes
INTEGERarguments acceptsINTEGER*2,INTEGER*4, orINTEGER*8.INTEGERintrinsics that takeINTEGERarguments return values ofINTEGERtype determined as follows - note that options-i2,-dbl, and-xtypemapmay 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
-dblin effect, a call toZCOSwith aDOUBLE COMPLEXargument will automatically become a call toCQCOSbecause 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,DOUBLEPRECISION,COMPLEX, orDOUBLECOMPLEXvalue 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
REALfunction returnsREAL*8- A call to a
DOUBLEPRECISIONfunction returnsREAL*8- A call to a
COMPLEXfunction returnsCOMPLEX*16- A call to a
DOUBLECOMPLEXfunction returnsCOMPLEX*16
- Other options that alter the data sizes of default data types are
-r8and-dbl, which also promoteDOUBLEtoQUAD. 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
Ais type integer, thenINT(A)isA.If
Ais 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
Ais type complex or double complex, then apply the above rule to the real part ofA.If
Ais type real, thenIFIX(A)is the same asINT(A).If
Ais type real, thenREAL(A)isA.If
Ais type integer or double precision, thenREAL(A)is as much precision of the significant part ofAas a real datum can contain.If
Ais type complex, thenREAL(A)is the real part ofA.If
Ais type double complex, thenREAL(A)is as much precision of the significant part of the real part ofAas a real datum can contain.If
Ais type double precision, thenDBLE(A)isA.If
Ais type integer or real, thenDBLE(A)is as much precision of the significant part ofAas a double precision datum can contain.If
Ais type complex, thenDBLE(A)is as much precision of the significant part of the real part ofAas a double precision datum can contain.If
Ais typeCOMPLEX*16, thenDBLE(A)is the real part ofA.If
Ais typeREAL*16, thenQREAL(A)isA.If
Ais type integer, real, or double precision, thenQREAL(A)is as much precision of the significant part ofAas aREAL*16datum can contain.If
Ais type complex or double complex, thenQREAL(A)is as much precision of the significant part of the real part ofAas aREAL*16datum can contain.If
Ais typeCOMPLEX*16orCOMPLEX*32, thenQREAL(A)is the real part ofA.If
Ais type complex, thenCMPLX(A)isA.If
Ais type integer, real, or double precision, thenCMPLX(A)isREAL(A) + 0i.If
A1andA2are type integer, real, or double precision, thenCMPLX(A1,A2)isREAL(A1) + REAL(A2)*i.If
Ais type double complex, thenCMPLX(A)isREAL( DBLE(A) ) + i*REAL( DIMAG(A) ).If
CMPLXhas two arguments, then they must be of the same type, and they may be one of integer, real, or double precision.If
CMPLXhas one argument, then it may be one of integer, real, double precision, complex,COMPLEX*16, orCOMPLEX*32.If
Ais typeCOMPLEX*16, thenDCMPLX(A)isA.If
Ais type integer, real, or double precision, thenDCMPLX(A)isDBLE(A) + 0i.If
A1andA2are type integer, real, or double precision, thenDCMPLX(A1,A2)isDBLE(A1) + DBLE(A2)*i.If
DCMPLXhas two arguments, then they must be of the same type, and they may be one of integer, real, or double precision.If
DCMPLXhas one argument, then it may be one of integer, real, double precision, complex,COMPLEX*16, orCOMPLEX*32.
ICHAR(A)is the position ofAin the collating sequence.The first position is 0, the last is
N-1, 0ICHAR(A)N-1, whereNis the number of characters in the collating sequence, andAis of type character of length one.
CHARandICHARare inverses in the following sense:
ICHAR(CHAR(I)) = I, for0IN-1CHAR(ICHAR(C)) = C, for any characterCcapable of representation in the processorA
COMPLEXvalue is expressed as an ordered pair of reals,(ar, ai), wherearis the real part, andaiis 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
COMPLEXis the principal value.If
ais ofCOMPLEXtype,CBRTresults inCOMPLEX RT1=(A, B), where:A0.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 inXwhereYstarts. That is, it is the starting position within character stringXof the first occurrence of character stringY.If
Ydoes not occur inX, thenINDEX(X,Y)is 0.If
LEN(X) < LEN(Y), thenINDEX(X,Y)is 0.
INDEXreturns defaultINTEGER*4data. If compiling for a 64-bit environment, the compiler will issue a warning if the result overflows theINTEGER*4data range. To useINDEXin a 64-bit environment with character strings larger than theINTEGER*4limit (2 Gbytes), theINDEXfunction and the variables receiving the result must be declaredINTEGER*8.
LENreturns the declared length of theCHARACTERargument variable. The actual value of the argument is of no importance.
LENreturns defaultINTEGER*4data. If compiling for a 64-bit environment, the compiler will issue a warning if the result overflows theINTEGER*4data range. To useLENin a 64-bit environment with character variables larger than theINTEGER*4limit (2 Gbytes), theLENfunction and the variables receiving the result must be declaredINTEGER*8.
LGE( X, Y )is true ifX=Y, or ifXfollowsYin the collating sequence; otherwise, it is false.
LGT( X, Y )is true ifXfollowsYin the collating sequence; otherwise, it is false.
LLE( X, Y )is true ifX=Y, or ifXprecedesYin the collating sequence; otherwise, it is false.
LLT( X, Y )is true ifXprecedesYin the collating sequence; otherwise, it is false.If the operands for
LGE,LGT,LLE, andLLTare 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.
LSHIFTshifts a1 logically left by a2 bits (inline code).
LRSHFTshifts a1 logically right by a2 bits (inline code).
RSHIFTshifts a1 arithmetically right by a2 bits.
ISHFTshifts a1 logically left if a2 > 0 and right if a2 < 0.The
LSHIFTandRSHIFTfunctions 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 + e1.0.
The
LOCfunction 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.
LOCreturns defaultINTEGER*4in 32-bit environments,INTEGER*8in 64-bit environments.
MALLOCis a library function and not an intrinsic. It too returns defaultINTEGER*4in 32-bit environments,INTEGER*8in 64-bit environments. However,MALLOCmust be explicitly declaredINTEGER*8when compiling for 64-bit environments.The value returned by
LOCorMALLOCshould be stored in variables typedPOINTER,INTEGER*4, orINTEGER*8in 64-bit environments. The argument toFREEmust be the value returned by a previous call toMALLOCand hence should have data typePOINTER,INTEGER*4, orINTEGER*8.
MALLOC64always takes anINTEGER*8argument (size of memory request in bytes) and always returns anINTEGER*8value. Use this routine rather thanMALLOCwhen compiling programs that must run in both 32-bit and 64-bit environments. The receiving variable must be declared eitherPOINTERorINTEGER*8.The
SIZEOFintrinsic cannot be applied to arrays of an assumed size, characters of a length that is passed, or subroutine calls or names.SIZEOFreturns defaultINTEGER*4data. If compiling for a 64-bit environment, the compiler will issue a warning if the result overflows theINTEGER*4data range. To useSIZEOFin a 64-bit environment with arrays larger than theINTEGER*4limit (2 Gbytes), theSIZEOFfunction 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.
f77copes with their existence by treating a specificINTEGER-to-INTEGERfunction 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
VMSFORTRANfunctions coerce to a particularINTEGERtype.
Functions Translated to a Generic Name
In some cases, each VMS-specific name is translated into an
f77generic 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 |