On 2020-07-05 15:15, Steven D'Aprano wrote:
[snip]
The only differences I can see are that my implementation of clamp()
supports None as a short-hand for infinity; and that it treats NANs
according to the standard, unlike the builtin min and max, which manage
to provide the worst of both possible words: they treat NANs according
to the order of the arguments, thus satisfying nobody and annoying
everybody.

The first part is, I think, important because with the min+max idiom, if
one side is unbounded, you can just leave it out:

     min(x, 1000)  # like clamp(x, -float('inf'), 1000)

but with clamp you have to supply *something* to mean "unbounded", and
using float("inf") is not very convenient. So it's just a tiny bit of
sugar to make the function more useful.

+1 to using None.

[snip]
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/3GVTX4TM2Z5VZXQLBMJTJQS6S6FK76J5/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to