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)

KMAX0

INTEGER(8)

INTEGER(8)

AKMAX0

INTEGER(8)

REAL(4)

IMAX1

REAL(4)

INTEGER(2)

MAX1 4, 5, 6

REAL(4)

INTEGER(4)

KMAX1

REAL(4)

INTEGER(8)

AMAX1 7

REAL(4)

REAL(4)

DMAX1

REAL(8)

REAL(8)

QMAX1

REAL(16)

REAL(16)

1These specific functions cannot be passed as actual arguments.

2Or JMAX0.

3Or AJMAX0.AMAX0 is the same as REAL (MAX).

4In Standard Fortran, AMAX0 and MAX1 are specific functions with no generic name. For compatibility with older versions of Fortran, these functions can also be specified as generic functions.

5Or JMAX1. MAX1 is the same as INT(MAX).

6The setting of compiler options specifying integer size can affect MAX1.

7The setting of compiler options specifying real size can affect AMAX1.

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