IBM Books

Engineering and Scientific Subroutine Library for AIX Version 3 Release 3: Guide and Reference

ISMAX and IDMAX--Position of the First or Last Occurrence of the Vector Element Having the Maximum Value

These subprograms find the position i of the first or last occurrence of a vector element having the maximum value.

You get the position of the first or last occurrence of an element by specifying positive or negative stride, respectively, for vector x. Regardless of the stride, the position i is always relative to the location specified in the calling sequence for vector x (in argument x).

Table 38. Data Types

x Subprogram
Short-precision real ISMAX
Long-precision real IDMAX

Syntax

Fortran ISMAX | IDMAX (n, x, incx)
C and C++ ismax | idmax (n, x, incx);
PL/I ISMAX | IDMAX (n, x, incx);

On Entry

n
is the number of elements in vector x. Specified as: a fullword integer; n >= 0.

x
is the vector x of length n. Specified as: a one-dimensional array of (at least) length 1+(n-1)|incx|, containing numbers of the data type indicated in Table 38.

incx
is the stride for vector x. Specified as: a fullword integer. It can have any value.

On Return

Function value
 

is the position i of the element in the array, where:

If incx >= 0, i is the position of the first occurrence.

If incx < 0, i is the position of the last occurrence.

Returned as: a fullword integer; 0 <= i <= n.

Note

Declare the ISMAX and IDMAX functions in your program as returning a fullword integer value.

Function

These subprograms find the first element xk, where k is defined as the smallest index k, such that:

xk = max{xj for j = 1, n}

By specifying a positive or negative stride for vector x, the first or last occurrence, respectively, is found in the array. The position i, returned as the value of the function, is always figured relative to the location specified in the calling sequence for vector x (in argument x). Therefore, depending on the stride specified for incx, i has the following values:

For incx >= 0, i = k
For incx < 0, i = n-k+1

See reference [79]. The result is returned as a function value. If n is 0, then 0 is returned as the value of the function.

Error Conditions

Computational Errors

None

Input-Argument Errors

n < 0

Example 1

This example shows a vector, x, with a stride of 1.

Function Reference and Input
              N   X  INCX
              |   |   |
IMAX = ISMAX( 6 , X , 1  )
 
X        =  (3.0, 4.0, 1.0, 8.0, 1.0, 8.0)

Output
IMAX     =  4

Example 2

This example shows a vector, x, with a stride greater than 1.

Function Reference and Input
              N   X  INCX
              |   |   |
IMAX = ISMAX( 4 , X , 2  )
 
X        =  (-3.0, . , 9.0, . , -8.0, . , 3.0)

Output
IMAX     =  2

Example 3

This example shows a vector, x, with a positive stride and two elements with the maximum value. The position of the first occurrence is returned.

Function Reference and Input
              N   X  INCX
              |   |   |
IMAX = ISMAX( 4 , X , 2  )
 
X        =  (2.0, . , 4.0, . , 4.0, . , 1.0)

Output
IMAX     =  2

Example 4

This example shows a vector, x, with a negative stride and two elements with the maximum value. The position of the last occurrence is returned. Processing begins at element X(7), which is 1.0.

Function Reference and Input
              N   X   INCX
              |   |    |
IMAX = ISMAX( 4 , X , -2  )
 
X        =  (2.0, . , 4.0, . , 4.0, . , 1.0)

Output
IMAX     =  3


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]