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]