On Sun, Jul 5, 2020 at 9:38 PM Steven D'Aprano <steve@pearwood.info> wrote:
> >I agree with you that `clamp(lower=x, value=NAN, upper= x)` should
> >return x.

Sorry Greg, on this point at least the IEEE-754 standard is firm: if a
function will return the same result for every non-NAN argument, then it
must return the same result for NAN arguments too.

    clamp(value, x, x)

will always return x for every finite and infinite value, so it must
return x for NANs too.

I strongly agree with Steven here.  Also about order-dependence in results of min() and max() being disturbing and contrary to IEEE-754.

... so, umm... Steven... statistics.median()?!

Btw, definitely +1 on math.clamp(value, *, lower=None, upper=None) .

-1 on built-in.  -0 on any other function signature.  Actually, I'm fine with math.clip() as well, but clamp seems more popular.