Table of contents
lstlti_c ( Last integer element less than )
SpiceInt lstlti_c ( SpiceInt x,
ConstSpiceInt * array )
Find the index of the largest array element less than
a given integer `x' in an array of non-decreasing integers.
VARIABLE I/O DESCRIPTION
-------- --- --------------------------------------------------
x I Upper bound value to search against.
n I Number of elements in `array'.
array I Array of possible lower bounds.
The function returns the index of the last element of `array' that
is less than `x'.
x is an integer value acting as an upper bound: the element
of `array' that is the greatest element less than `x' is to
n is the total number of elements in `array'.
array is an array of integers that forms a non-decreasing
sequence. The elements of array need not be distinct.
The function returns the index of the highest-indexed element in
the input array that is less than `x'. The routine assumes the array
elements are sorted in non-decreasing order.
Indices range from 0 to n-1.
If all elements of `array' are greater than or equal to `x', the
routine returns the value -1. If `n' is less than or equal to zero,
the routine returns the value -1.
1) If `n' is less than or equal to zero, the function returns -1.
This case is not treated as an error.
2) If the input array is not sorted in non-decreasing order, the
output of this routine is undefined. No error is signaled.
This routine uses a binary search algorithm and so requires
at most on the order of
steps to compute the value of lstlti_c.
Note: If you need to find the first element of the array that is
greater than or equal to `x', simply add 1 to the result returned by
this function and check to see if the result is within the array
bounds given by `n'.
1) Let array be assigned the following values:
array = -2;
array = -2;
array = 0;
array = 1;
array = 1;
array = 11;
The table below demonstrates the behavior of lstlti_c:
Call Returned Value
lstlti_c ( -3, 6, array ) -1
lstlti_c ( -2, 6, array ) -1
lstlti_c ( 0, 6, array ) 1
lstlti_c ( 1, 6, array ) 2
lstlti_c ( 12, 6, array ) 5
1) If the sequence of integer numbers in the input array `array' is
not non-decreasing, the program will run to completion but the
index found will not mean anything.
N.J. Bachman (JPL)
J. Diaz del Rio (ODC Space)
H.A. Neilan (JPL)
W.L. Taber (JPL)
-CSPICE Version 1.0.1, 01-NOV-2021 (JDR)
Edited the header to comply with NAIF standard. Corrected -Index_Entries
entry. Improved -Detailed_Input, -Detailed_Output, -Particulars,
-Exceptions and -Restrictions sections.
-CSPICE Version 1.0.0, 09-JUL-2002 (NJB) (HAN) (WLT)
last integer element less_than