powered by
Finds the index of the bin a number belongs to using binary search.
binarySearch_bin(arr, l, r, x)
The index i such that arr[i] <= x <= arr[i+1].
i
arr[i] <= x <= arr[i+1]
A vector of size at least 2.
An integer between 1 and length(arr). Must be smaller than 1.
length(arr)
1
An integer between 1 and length(arr). Must be larger than l.
l
A number. Must be within the range of [arr[l], arr[r]].
arr[l]
arr[r]
Finds the smallest index i such that arr[i] <= x <= arr[i+1].
binarySearch_bin(1:10, 1, 10, seq(1, 10, by=0.5)) binarySearch_bin(1:10, 5, 8, seq(5, 8, by=0.5))
Run the code above in your browser using DataLab