Given a real (n), a maximum value this real can be (upper), and a minimum value this real can be (lower), how can we most efficiently clip n, such that it remains between lo
C++17 is expected to add a clamp function. Courtesy of cppreference.com:
template constexpr const T& clamp( const T& v, const T& lo, const T& hi ); template constexpr const T& clamp( const T& v, const T& lo, const T& hi, Compare comp );