[New-bugs-announce] [issue41408] Add a `clamp` function to the `math` module

Avinash Maddikonda report at bugs.python.org
Mon Jul 27 08:28:33 EDT 2020


New submission from Avinash Maddikonda <svasssakavi at gmail.com>:

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>`)

----------
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 <report at bugs.python.org>
<https://bugs.python.org/issue41408>
_______________________________________


More information about the New-bugs-announce mailing list