
Aug. 4, 2016
5:58 p.m.
On Thu, Aug 4, 2016, at 12:24, Alexander Belopolsky wrote:
On Thu, Aug 4, 2016 at 11:48 AM, Victor Stinner <victor.stinner@gmail.com> wrote:
When I really need such function, I define it like this:
def clamp(min_val, value, max_val): return min(max(min_val, value), max_val)
and your colleague next door defines it like this:
def clamp(min_val, value, max_val): return min(max_val, max(value , min_val))
Ideally min and max should themselves be defined in a way that makes that not an issue (or perhaps only an issue for different-signed zero values)
and a third party library ships
def clamp(min_val, value, max_val): return max(min(max_val, value), min_val)
That one is more of an issue, though AIUI only so when min_val > max_val.