On 04/07/2020 02:01, MRAB wrote:
Should it raise an exception if minimum > maximum? If it doesn't, then
you'll get a different answer depending on whether it's
`min(max(value, minimum), maximum)` or `max(min(value, maximum),
minimum)`.
Yes, I'd expect ValueError if min > max or max < min.
On 04/07/2020 02:03, Steven D'Aprano wrote:
Bottom line is that passing a NAN as the lower or upper bound should
treat it as equivalent to "unbounded", that is, equivalent to ±∞. The
beauty of that is that it can be implemented without explicitly
testing for NANs, which involves unnecessary conversions to float, and
may even raise an exception. Here is the version I use: ... Features:
* uses None as a convenient alias for unbounded; * treats NANs
according to the standard; * requires no explicit conversion to float
or testing for NANs; * so this will work with Fractions and Decimals.
I'm not opposed to this but wouldn't the programmer expect it to behave
much like a shorthand of the existing min() + max()? Should these two
then be modified to exhibit the same behaviour? I'd find it inconsistent
if clamp() did but min() and max() didn't.
On 04/07/2020 02:50, Christopher Barker wrote:
FWIW, numpy calls it "clip"
I feel clip fits best with the idea of a collection to... clip.
`clamp()` would work with scalars, for which the word clip might not be
clear at a glance. While I have no strong feelings in favour of clamp, I
do think it would be better than clip (but maybe it's just my experience
with CSS speaking). As far as other options go, I agree with Mr
D'Aprano's objection to `minmax`, and I'd like to toss a possible
`coerce` (similarly used in Kotlin) into the hat. Maybe someone has
better names in mind?
_______________________________________________
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/DE64IZNX7OZGNRX6YLFDHBPYO6CBBIGB/
Code of Conduct: http://python.org/psf/codeofconduct/