import numpy as np

arr = np.array([0.23, 2.32, 4.04, 5.02, 6.84, 10.12, 10.34, 11.93,12.44])

def binary_search(arr, val):
	# val must be in the closed interval between arr[i-1] and arr[i],
	# unless one of i-1 or i is beyond the bounds of the array.
	i = np.searchsorted(arr, val)
	
	if i == 0:
		# Smaller than the smallest element
		return i
	elif i == len(arr):
		# Bigger than the biggest element
		return i - 1
	elif val - arr[i - 1] <= arr[i] - val:
		# At least as close to arr[i - 1] as arr[i]
		return i - 1
	else:
		# Closer to arr[i] than arr[i - 1]
		return i

cases = [10, 12, 100, 10.12, 12.43, 0.5]
print(*[binary_search(arr, c) for c in cases], sep=',')
print(*[arr[binary_search(arr, c)] for c in cases], sep=',')