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
Why rewrite something that's already been written for you?
#include boost::algorithm::clamp(n, lower, upper);
As of C++17, this is now part of the STL:
#include std::clamp(n, lower, upper);