findSpan function
Implementation
int findSpan(int p, num u, List<double> U ) {
final n = U.length - p - 1;
if ( u >= U[ n ] ) {
return n - 1;
}
if ( u <= U[ p ] ) {
return p;
}
num low = p;
num high = n;
int mid = ( ( low + high ) / 2 ).floor();
while ( u < U[ mid ] || u >= U[ mid + 1 ] ) {
if ( u < U[ mid ] ) {
high = mid;
}
else {
low = mid;
}
mid = ( ( low + high ) / 2 ).floor();
}
return mid;
}