Start of change

BINSEARCH

BINSEARCH performs a binary search of an array for a specified key value by using a simple compare and returns a size_t value.

Read syntax diagramSkip visual syntax diagram
>>-BINSEARCH(x,y-+-----------+-)-------------------------------><
                 '-,n-+----+-'     
                      '-,m-'       

x
An expression that specifies the target array that would be searched within. x must be a one-dimensional array and the elements of x must be in ascending order. If x is an array of NONVARYING BIT, it must be aligned.
y
An expression that specifies the key value to be searched for.
n
An expression that specifies the index of the first array element to be examined. It defaults to LBOUND(x).
m
An expression that specifies the number of to-be-examined array elements. The counting starts with the nth and defaults to HBOUND(x) – n + 1.
The elements of the array x and the key value must satisfy one of the following:

The returned value is the relative index of the key value in this array. If the key value y is not found in the array, the returned size_t value is zero.

The relative index is the index if the array has a lower bound of 1. Therefore, the true index would be calculated as: the returned value + LBOUND(x) – 1. For example:
End of change