Sun Studio 12: Fortran Library Reference

# 3.1 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.

## 3.1.1 Arithmetic Functions

Table 3–1 Fortran 77 Arithmetic Functions

Intrinsic Function

Definition

No. of

Args.

Generic

Name

Specific

Names

Argument

Type

Function Type

Absolute value

See Note (6).

|a| =

(ar2+ai2)1/2

ABS

IABS

ABS

DABS

CABS

QABS ¤

ZABS ¤

CDABS ¤

CQABS ¤

INTEGER

REAL

DOUBLE

COMPLEX

REAL*16

DOUBLE COMPLEX

DOUBLE COMPLEX

COMPLEX*32

INTEGER

REAL

DOUBLE

REAL

REAL*16

DOUBLE

DOUBLE

REAL*16

Truncation

See Note (1).

int(a)

AINT

AINT

DINT

QINT ¤

REAL

DOUBLE

REAL*16

REAL

DOUBLE

REAL*16

Nearest whole number

int(a+.5) if a ≥ 0

int(a-.5) if a < 0

ANINT

ANINT

DNINT

QNINT ¤

REAL

DOUBLE

REAL*16

REAL

DOUBLE

REAL*16

Nearest integer

int(a+.5) if a ≥ 0

int(a-.5) if a < 0

NINT

NINT

IDNINT

IQNINT ¤

REAL

DOUBLE

REAL*16

INTEGER

INTEGER

INTEGER

Remainder

See Note (1).

a1-int(a1/a2)*a2

MOD

MOD

AMOD

DMOD

QMOD ¤

INTEGER

REAL

DOUBLE

REAL*16

INTEGER

REAL

DOUBLE

REAL*16

Transfer of sign

|a1| if a2 ≥ 0

-|a1| if a2 < 0

SIGN

ISIGN

SIGN

DSIGN

QSIGN ¤

INTEGER

REAL

DOUBLE

REAL*16

INTEGER

REAL

DOUBLE

REAL*16

Positive difference

a1-a2 if a1 > a2

0 if a1≤ a2

DIM

IDIM

DIM

DDIM

QDIM ¤

INTEGER

REAL

DOUBLE

REAL*16

INTEGER

REAL

DOUBLE

REAL*16

a1 * a2

-

DPROD

QPROD ¤

REAL

DOUBLE

DOUBLE

REAL*16

Choosing largest value

max(a1, a2, …)

≥2

MAX

MAX0

AMAX1

DMAX1

QMAX1 ¤

INTEGER

REAL

DOUBLE

REAL*16

INTEGER

REAL

DOUBLE

REAL*16

AMAX0

AMAX0

INTEGER

REAL

MAX1

MAX1

REAL

INTEGER

Choosing smallest value

min(a1, a2, …)

≥2

MIN

MIN0

AMIN1

DMIN1

QMIN1 ¤

INTEGER

REAL

DOUBLE

REAL*16

INTEGER

REAL

DOUBLE

REAL*16

AMIN0

AMIN0

INTEGER

REAL

MIN1

MIN1

REAL

INTEGER

## 3.1.2 Type Conversion Functions

Table 3–2 Fortran 77 Type Conversion Functions

Conversion to

No. of Args

Generic Name

Specific

Names

Argument Type

Function Type

INTEGER

 ` See Note (1).`

INT

-

INT

IFIX

IDINT

-

-

-

IQINT ¤

INTEGER

REAL

REAL

DOUBLE

COMPLEX

COMPLEX*16

COMPLEX*32

REAL*16

INTEGER

INTEGER

INTEGER

INTEGER

INTEGER

INTEGER

INTEGER

INTEGER

REAL

 ` See Note (2).`

REAL

REAL

FLOAT

-

SNGL

SNGLQ ¤

-

-

-

FLOATK

INTEGER

INTEGER

REAL

DOUBLE

REAL*16

COMPLEX

COMPLEX*16

COMPLEX*32

INTEGER*8

REAL

REAL

REAL

REAL

REAL

REAL

REAL

REAL

REAL*4

DOUBLE

 ``` See Note (3). ```

DBLE

DBLE

DFLOAT

DFLOATK

DREAL ¤

-

-

-

-

-

DBLEQ ¤-

INTEGER

INTEGER

INTEGER*8

REAL

DOUBLE

COMPLEX

COMPLEX*16

REAL*16

COMPLEX*32REAL*16COMPLEX*32

DOUBLE PRECISION

DOUBLE PRECISION

DOUBLE PRECISION

DOUBLE PRECISION

DOUBLE PRECISION

DOUBLE PRECISION

DOUBLE PRECISION

DOUBLE PRECISION

DOUBLE PRECISIONDOUBLE PRECISION

DOUBLE PRECISION

 ```REAL*16 See Note (3’). ```

QREAL¤

QEXT ¤

QREAL ¤

QFLOAT ¤

-

QEXT ¤

QEXTD ¤

-

-

-

-

INTEGER

INTEGER

REAL

INTEGER

DOUBLE

REAL*16

COMPLEX

COMPLEX*16

COMPLEX*32

REAL*16

REAL*16

REAL*16

REAL*16

REAL*16

REAL*16

REAL*16

REAL*16

REAL*16

 ```COMPLEX See Notes (4) and (8). ```

1 or 2

 `CMPLX`

-

-

-

-

-

-

-

INTEGER

REAL

DOUBLE

REAL*16

COMPLEX

COMPLEX*16

COMPLEX*32

COMPLEX

COMPLEX

COMPLEX

COMPLEX

COMPLEX

COMPLEX

COMPLEX

 ```DOUBLE COMPLEX See Note (8). ```

1 or 2

 `DCMPLX@`

-

-

-

-

-

-

-

INTEGER

REAL

DOUBLE

REAL*16

COMPLEX

COMPLEX*16

COMPLEX*32

DOUBLE COMPLEX

DOUBLE COMPLEX

DOUBLE COMPLEX

DOUBLE COMPLEX

DOUBLE COMPLEX

DOUBLE COMPLEX

DOUBLE COMPLEX

 ```COMPLEX*32 See Note (8). ```

1 or 2

 `QCMPLX@`

-

-

-

-

-

-

-

INTEGER

REAL

DOUBLE

REAL*16

COMPLEX

COMPLEX*16

COMPLEX*32

COMPLEX*32

COMPLEX*32

COMPLEX*32

COMPLEX*32

COMPLEX*32

COMPLEX*32

COMPLEX*32

 ```INTEGER See Note (5). ```

 ```- -```

ICHAR

IACHAR ¤

CHARACTER

INTEGER

 ```CHARACTER See Note (5). ```

 ```- -```

CHAR

ACHAR ¤

INTEGER

CHARACTER

On an ASCII platform, including Sun systems:

• ACHAR is a nonstandard synonym for CHAR

• IACHAR is a nonstandard synonym for ICHAR

On a non-ASCII platform, ACHAR and IACHAR were intended to provide a way to deal directly with ASCII.

## 3.1.3 Trigonometric Functions

Table 3–3 Fortran 77 Trigonometric Functions

Intrinsic Function

Definition

Args

Generic Name

Specific

Names

Argument Type

Function Type

Sine

See Note (7).

sin(a)

SIN

SIN

DSIN

QSIN ¤

CSIN

ZSIN ¤

CDSIN ¤

CQSIN ¤

REAL

DOUBLE

REAL*16

COMPLEX

DOUBLE COMPLEX

DOUBLE COMPLEX

COMPLEX*32

REAL

DOUBLE

REAL*16

COMPLEX

DOUBLE COMPLEX

DOUBLE COMPLEX

COMPLEX*32

Sine (degrees)

See Note (7).

sin(a)

SIND ¤

SIND ¤

DSIND ¤

QSIND ¤

REAL

DOUBLE

REAL*16

REAL

DOUBLE

REAL*16

Cosine

See Note (7).

cos(a)

COS

COS

DCOS

QCOS ¤

CCOS

ZCOS ¤

CDCOS ¤

CQCOS ¤

REAL

DOUBLE

REAL*16

COMPLEX

DOUBLE COMPLEX

DOUBLE COMPLEX

COMPLEX*32

REAL

DOUBLE

REAL*16

COMPLEX

DOUBLE COMPLEX

DOUBLE COMPLEX

COMPLEX*32

Cosine (degrees)

See Note (7).

cos(a)

COSD ¤

COSD ¤

DCOSD ¤

QCOSD ¤

REAL

DOUBLE

REAL*16

REAL

DOUBLE

REAL*16

Tangent

See Note (7).

tan(a)

TAN

TAN

DTAN

QTAN ¤

REAL

DOUBLE

REAL*16

REAL

DOUBLE

REAL*16

Tangent (degrees)

See Note (7).

tan(a)

TAND ¤

TAND ¤

DTAND ¤

QTAND ¤

REAL

DOUBLE

REAL*16

REAL

DOUBLE

REAL*16

Arcsine

See Note (7).

arcsin(a)

ASIN

ASIN

DASIN

QASIN ¤

REAL

DOUBLE

REAL*16

REAL

DOUBLE

REAL*16

Arcsine (degrees)

See Note (7).

arcsin(a)

ASIND ¤

ASIND ¤

DASIND ¤

QASIND ¤

REAL

DOUBLE

REAL*16

REAL

DOUBLE

REAL*16

Arccosine

See Note (7).

arccos(a)

ACOS

ACOS

DACOS

QACOS ¤

REAL

DOUBLE

REAL*16

REAL

DOUBLE

REAL*16

Arccosine (degrees)

See Note (7).

arccos(a)

ACOSD ¤

ACOSD ¤

DACOSD ¤

QACOSD ¤

REAL

DOUBLE

REAL*16

REAL

DOUBLE

REAL*16

Arctangent

See Note (7).

arctan(a)

ATAN

ATAN

DATAN

QATAN ¤

REAL

DOUBLE

REAL*16

REAL

DOUBLE

REAL*16

arctan

(a1/a2)

ATAN2

ATAN2

DATAN2

QATAN2 ¤

REAL

DOUBLE

REAL*16

REAL

DOUBLE

REAL*16

Arctangent (degrees)

See Note (7).

arctan(a)

ATAND ¤

ATAND ¤

DATAND ¤

QATAND ¤

REAL

DOUBLE

REAL*16

REAL

DOUBLE

REAL*16

arctan

(a1/a2)

ATAN2D¤

ATAN2D ¤

DATAN2D ¤

QATAN2D ¤

REAL

DOUBLE

REAL*16

REAL

DOUBLE

REAL*16

Hyperbolic Sine

See Note (7).

sinh(a)

SINH

SINH

DSINH

QSINH ¤

REAL

DOUBLE

REAL*16

REAL

DOUBLE

REAL*16

Hyperbolic Cosine

See Note (7).

cosh(a)

COSH

COSH

DCOSH

QCOSH ¤

REAL

DOUBLE

REAL*16

REAL

DOUBLE

REAL*16

Hyperbolic Tangent

See Note (7).

tanh(a)

TANH

TANH

DTANH

QTANH ¤

REAL

DOUBLE

REAL*16

REAL

DOUBLE

REAL*16

## 3.1.4 Other Mathematical Functions

Table 3–4 Other Fortran 77 Mathematical Functions

Intrinsic Function

Definition

No. of Args.

Generic Name

Specific Names

Argument Type

Function Type

Imaginary part of a complex number

See Note (6).

ai

IMAG

AIMAG

DIMAG ¤

QIMAG ¤

COMPLEX

DOUBLE COMPLEX

COMPLEX*32

REAL

DOUBLE

REAL*16

Conjugate of a complex number

See Note (6).

(ar, -ai)

CONJG

CONJG

DCONJG ¤

QCONJG ¤

COMPLEX

DOUBLE COMPLEX

COMPLEX*32

COMPLEX

DOUBLE COMPLEX

COMPLEX*32

Square root

a**(1/2)

SQRT

SQRT

DSQRT

QSQRT ¤

CSQRT

ZSQRT ¤

CDSQRT ¤

CQSQRT ¤

REAL

DOUBLE

REAL*16

COMPLEX

DOUBLE COMPLEX

DOUBLE COMPLEX

COMPLEX*32

REAL

DOUBLE

REAL*16

COMPLEX

DOUBLE COMPLEX

DOUBLE COMPLEX

COMPLEX*32

Cube root

See Note(8’).

a**(1/3)

CBRT

CBRT ¤

DCBRT ¤

QCBRT ¤

CCBRT ¤

ZCBRT ¤

CDCBRT ¤

CQCBRT ¤

REAL

DOUBLE

REAL*16

COMPLEX

DOUBLE COMPLEX

DOUBLE COMPLEX

COMPLEX*32

REAL

DOUBLE

REAL*16

COMPLEX

DOUBLE COMPLEX

DOUBLE COMPLEX

COMPLEX*32

Exponential

e**a

EXP

EXP

DEXP

QEXP ¤

CEXP

ZEXP ¤

CDEXP ¤

CQEXP ¤

REAL

DOUBLE

REAL*16

COMPLEX

DOUBLE COMPLEX

DOUBLE COMPLEX

COMPLEX*32

REAL

DOUBLE

REAL*16

COMPLEX

DOUBLE COMPLEX

DOUBLE COMPLEX

COMPLEX*32

Natural logarithm

log(a)

LOG

ALOG

DLOG

QLOG ¤

CLOG

ZLOG ¤

CDLOG ¤

CQLOG ¤

REAL

DOUBLE

REAL*16

COMPLEX

DOUBLE COMPLEX

DOUBLE COMPLEX

COMPLEX*32

REAL

DOUBLE

REAL*16

COMPLEX

DOUBLE COMPLEX

DOUBLE COMPLEX

COMPLEX*32

Common logarithm

log10(a)

LOG10

ALOG10

DLOG10

QLOG10 ¤

REAL

DOUBLE

REAL*16

REAL

DOUBLE

REAL*16

Error function(See note below)

erf(a)

ERF

ERF ¤

DERF ¤

REAL

DOUBLE

REAL

DOUBLE

Error function

1.0 - erf(a)

ERFC

ERFC ¤

DERFC ¤

REAL

DOUBLE

REAL

DOUBLE

• The error function: 2/sqrt(pi) x integral from 0 to a of exp(-t*t) dt