v1 if val is closer to v1 than to v2, v2 otherwise
the value
first value to compare to
second value to compare to