Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference

ID 767251
Date 11/07/2023
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

MAX

Elemental Intrinsic Function (Generic): Returns the maximum value of the arguments.

result = MAX (a1,a2[,a3]...)

a1, a2, a3

(Input) All must have the same type (integer, real, or character) and kind parameters.

Results

For arguments of character type, the result type is character, and the length of the result is the length of the longest argument. For MAX0, AMAX1, DMAX1, QMAX1, IMAX0, JMAX0, and KMAX0, the result type is the same as the arguments. For MAX1, IMAX1, JMAX1, and KMAX1, the result type is integer. For AMAX0, AIMAX0, AJMAX0, and AKMAX0, the result type is real. The value of the result is that of the largest argument. For character arguments, the comparison is done using the ASCII collating sequence. If the selected argument is shorter than the longest argument, the result is extended to the length of the longest argument by inserting blank characters on the right.

The Fortran standard does not define the behavior if one or more real arguments is a NaN and at least one argument is not a NaN. Depending on the order of the arguments, the result may be either the maximum non-NaN value or a NaN.

Specific Name 1

Argument Type

Result Type

INTEGER(1)

INTEGER(1)

IMAX0

INTEGER(2)

INTEGER(2)

AIMAX0

INTEGER(2)

REAL(4)

MAX0 2

INTEGER(4)

INTEGER(4)

AMAX0 3, 4

INTEGER(4)

REAL(4)

Example

MAX (2.0, -8.0, 6.0) has the value 6.0.

MAX (14, 32, -50) has the value 32.

The following shows another example:

INTEGER m1, m2 REAL r1, r2 m1 = MAX(5, 6, 7) ! returns 7 m2 = MAX1(5.7, 3.2, -8.3) ! returns 5 r1 = AMAX0(5, 6, 7) ! returns 7.0 r2 = AMAX1(6.4, -12.2, 4.9) ! returns 6.4