The SDL Component Suite is an industry leading collection of components supporting scientific and engineering computing. Please visit the SDL Web site for more information....


Class: none
Declaration: function FindInSortedArray (Value: double; Arr: TDoubleArray; Ascending: boolean): integer;

The function FindInSortedArray searches the sorted 1-dimensional array for the element which is closest to Value and returns the index of the found element as the function value. The parameter Ascending indicates the sort order of the array elements (TRUE = ascending, FALSE = descending).

The function returns the following error codes:

≥0 ... everything is OK, the returned number is the index of the closest element
 -1 ... Arr has zero size
 -2 ... Value is outside the range of the array values

Hint: The search algorithm in FindInSortedArray is based on a binary search, which is considerably faster, but which requires the array to be sorted. If the array elements are not sorted or not sorted according to the parameter Ascending, the search will not succeed, even if there is a matching cell in the array.

Last Update: 2020-Jul-22