To be honest, @Grunalin, your solution is fine ... but you could put it in a function to clip ... or clamp ... the solution between limits. std::clamp(), as in @JLBorges' post in that link, will do the job if you have a c++17-compliant compiler.
FWIW, I tend to use max-min, e.g. max( low, min( high, value ) )
simply because that is how it tends to be written in scientific papers, not computer code.
(Since max and min are defined in the standard library in <algorithm> you may want to choose some alternative names of variables.)
I got loads to read through to decide the approach i want. I will be calling this function a lot and the way I wrote seems quite inefficent. Will read up/ test each way i guess. Thx again guys.
There's really not much else you can do [outside of external refactoring]. max() and min() functions are still going to be calling if-statements. Using clamp instead of min()+max() just saves you 1x if-branch for best-case scenarios.
One thing one could do, depending on the logic of the program, would be some sort of lazy evaluation, where you don't clamp values until necessary.
"seems quite inefficient"
I would do actual, repeatable performance testing before you make this conclusion. It could very well be the process/subroutine as a whole that's slow and not just this one bit of it.