Issue41408
Created on 2020-07-27 12:28 by SFM61319, last changed 2022-04-11 14:59 by admin. This issue is now closed.
| Messages (6) | |||
|---|---|---|---|
| msg374373 - (view) | Author: Avinash Maddikonda (SFM61319) * | Date: 2020-07-27 12:28 | |
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..
<And some extra explanatory documentation with examples>
"""
return max(minimum, min(value, maximum))
```
Because even `C++` has built-in clamp function (`std::clamp`) (which can be used using `#include <math.h>`)
|
|||
| msg374376 - (view) | Author: Karthikeyan Singaravelan (xtreak) * ![]() |
Date: 2020-07-27 13:18 | |
This seems to be a duplicate of https://bugs.python.org/issue36788 |
|||
| msg374388 - (view) | Author: Avinash Maddikonda (SFM61319) * | Date: 2020-07-27 15:37 | |
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? |
|||
| msg374391 - (view) | Author: Karthikeyan Singaravelan (xtreak) * ![]() |
Date: 2020-07-27 15:53 | |
I will leave it to math module experts to keep it open or close it. There wasn't strong consensus on adding it math module either without a discussion in python-ideas https://bugs.python.org/msg358789. |
|||
| msg374393 - (view) | Author: Avinash Maddikonda (SFM61319) * | Date: 2020-07-27 16:00 | |
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) |
|||
| msg374396 - (view) | Author: Avinash Maddikonda (SFM61319) * | Date: 2020-07-27 16:23 | |
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. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:59:34 | admin | set | github: 85580 |
| 2020-07-28 07:32:49 | mark.dickinson | set | superseder: Add clamp() function to builtins resolution: rejected -> duplicate |
| 2020-07-27 16:23:46 | SFM61319 | set | status: open -> closed resolution: rejected stage: resolved |
| 2020-07-27 16:23:28 | SFM61319 | set | messages: + msg374396 |
| 2020-07-27 16:00:01 | SFM61319 | set | messages: + msg374393 |
| 2020-07-27 15:53:25 | xtreak | set | nosy:
+ rhettinger, mark.dickinson, stutzbach messages: + msg374391 |
| 2020-07-27 15:37:53 | SFM61319 | set | messages: + msg374388 |
| 2020-07-27 13:18:49 | xtreak | set | nosy:
+ xtreak messages: + msg374376 |
| 2020-07-27 12:28:33 | SFM61319 | create | |
