package rrc

func searchVL(V []float64, Sik float64) int {
	left, right := 0, len(V)-2

	// if Sik < V[0] || Sik > V[len(V)-1] {
	// 	return -1
	// }

	for left <= right {
		mid := left + (right-left)/2
		// Check if Sik is between V[mid] and V[mid+1]
		if V[mid]-1e-6 <= Sik && Sik <= V[mid+1]+1e-6 {
			return mid
		} else if Sik < V[mid] {
			right = mid - 1
		} else if Sik == V[mid] {
			return mid
		} else {
			left = mid + 1
		}
	}

	// Return -1 if no such position is found
	return -1
}
