Comment 4 for bug 1209521

Revision history for this message
Gary Kennedy (gkennedy) wrote :

The problem is the use if Sorting.binarySearchFromTo, it is not quite equivelent of std::upper_bound, specifically Sorting.binarySearchfromTo will return a negative number when the value is not found on the sorted vector. The javadoc on the return value says it more exactly...

"index of the search key, if it is contained in the list; otherwise, (-(insertion point) - 1). The insertion point is defined as the the point at which the value would be inserted into the list: the index of the first element greater than the key, or list.length, if all elements in the list are less than the specified key. Note that this guarantees that the return value will be >= 0 if and only if the key is found."

for interest, there is also a simailar locate method on interpolation methods in Numerical Recipes in C.