error calculating midpoint in binary search