speed up snapping to closest value by using dichotomy
transform interval to values when possible