While I agree that having "clamp" operate on all Python types is a "good thing"[*], there is a complication.

If it were put in the math module, then it would pretty much have to be a floating point function. At least that was the case for math.isclose(). My first prototype of isclose() was written in Python, and carefully designed to work with any type (well, any numeric type -- i.e. Decimal and Fraction. But once it was decided to add it to the math module, that got removed, for (I think) two reasons.

1) The math module is written in C, and Guido at least (he was still BDFL then) rejected the idea of refactoring it to allow Python components (yes, that was proposed, and even started by, I think, Victor Stiner). Yes, you can write generic functions in C, but it's a lot more of a pain.

2) The rest of the math module is currently all about floats already, having begun as a wrapper around the C math library. So that continues. (there was a version added to cmath as well).

If it doesn't live in the math module, then all this is irrelevant.

-CHB

[*] Honestly, while you *could* use clamp() with any comparable objects, I really don't see a use case for anything non-numerical, but why not?



On Mon, Jul 6, 2020 at 9:40 AM Bruce Leban <bruce@leban.us> wrote:

On Mon, Jul 6, 2020 at 4:27 AM Richard Damon <Richard@damon-family.org> wrote:

> Supported, yes. Recommended, no. IEEE-754 specifies that the *minimum
> *operation propagates NaNs while the /alternate /*minimumNumber
> *operation drops NaNs.

It should be noted, this is a change in the Standard that is just 1 year
old. The previous version did define minimum as similar to the
minimumNumber version.

Thanks for this info. I really dislike "standards" being hidden behind paywalls. I believe that contributes to people disregarding them. And it's sloppy to not highlight changes in a new version of a standard.

--- Bruce
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-leave@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/TOJMIC3SYRAGFTASMZGXUKIK7OMBY4JP/
Code of Conduct: http://python.org/psf/codeofconduct/


--
Christopher Barker, PhD

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython