HTBasic Help
×
Menu
Index
Crossing
Find the point in an array that crosses a threshold.
 
Loading        LOADSUB ALL FROM "CROSS.HTS"
or LOADSUB FROM "MATHLIB.HTS"
 
Usage                INTEGER K,N,S
REAL A(*),T
K=FNCrossing(A(*),T,S,N)
 
Description                
FNCrossing finds the nth time that the values in the array A, beginning with element s, cross the threshold value t and returns the index of the crossing. If n is negative, the search is done backwards from the sth element for the nth crossing; otherwise, the search is done forward from the sth element.
 
The values in A are considered to cross t when an element of A is equal to t and the previous element was not equal to t, when the first element in A equals t, when an element in A is greater than t and the previous element was less than t, or when an element in A is less than t and the previous element was greater than t. In the latter two cases, the crossing occurs between two elements in A; the value returned is the index of the element after the crossing.
 
The value of s and the value returned are with reference to the lower bound specified when A was dimensioned or the value specified in the OPTION BASE in effect when A was dimensioned, if no lower bound was specified.
 
If the portion of A from s to the end of A (n > 0) or the portion of A from s to the beginning of A (n < 0) contains fewer than n crossings of the value of t, -1 is returned.
 
Errors                
FNCrossing causes an HTBasic error if its arguments are not of the types shown in the USAGE section, above, or if s is not in the range of the subscripts of A.