[issue41408] Add a `clamp` function to the `math` module
New submission from Avinash Maddikonda : Add a `clamp` function to the `math` module which does something like this: ```py def clamp(value=0.5, minimum=0, maximum=1): """Clamps the *value* between the *minimum* and *maximum* and returns it.. """ return max(minimum, min(value, maximum)) ``` Because even `C++` has built-in clamp function (`std::clamp`) (which can be used using `#include `) -- components: Library (Lib) messages: 374373 nosy: SFM61319 priority: normal severity: normal status: open title: Add a `clamp` function to the `math` module type: enhancement versions: Python 3.10 ___ Python tracker <https://bugs.python.org/issue41408> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue41408] Add a `clamp` function to the `math` module
Avinash Maddikonda added the comment: Oh, I didn't know that. But I was thinking of adding it to the math module and not as a built-in method. I mean, it is definitely more useful than copysign, right? -- ___ Python tracker <https://bugs.python.org/issue41408> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue41408] Add a `clamp` function to the `math` module
Avinash Maddikonda added the comment: So should I delete/reject this now? Because I think it would be more useful than functions like copysign (I mean copysign can be written easily without confusion, but clamp is confusing sometimes as the max function takes minimum and the min of value and the maximum, and yet we have a copysign function but not a clamp built-in or a math module function). (I'll delete/reject if you guys want me to, np) -- ___ Python tracker <https://bugs.python.org/issue41408> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue41408] Add a `clamp` function to the `math` module
Avinash Maddikonda added the comment: Okay, I'm rejecting this issue. But please let me know/contribute if anyone is going to add a clamp function as a built-in method or a math module function. -- ___ Python tracker <https://bugs.python.org/issue41408> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue41408] Add a `clamp` function to the `math` module
Change by Avinash Maddikonda : -- resolution: -> rejected stage: -> resolved status: open -> closed ___ Python tracker <https://bugs.python.org/issue41408> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com