constant-time distance_compare for infinite ranges