IBM Books

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

ISAMIN and IDAMIN--Position of the First or Last Occurrence of the Vector Element Having Minimum Absolute Value

These subprograms find the position i of the first or last occurrence of a vector element having the minimum absolute 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 37. Data Types

x Subprogram
Short-precision real ISAMIN
Long-precision real IDAMIN

Syntax

Fortran ISAMIN | IDAMIN (n, x, incx)
C and C++ isamin | idamin (n, x, incx);
PL/I ISAMIN | IDAMIN (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 37.

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 ISAMIN and IDAMIN 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| = min{|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
               |   |    |
IMIN = ISAMIN( 6 , X ,  1  )
 
X        =  (3.0, 4.0, 1.0, 8.0, 1.0, 3.0)

Output
IMIN     =  3

Example 2

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

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

Output
IMIN     =  1

Example 3

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

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

Output
IMIN     =  2

Example 4

This example shows a vector, x, with a negative stride and two elements with the minimum absolute 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
               |   |    |
IMIN = ISAMIN( 4 , X , -2  )
 
X        =  (2.0, . , -1.0, . , 4.0, . , 1.0)

Output
IMIN     =  4


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