Sfoglia il codice sorgente

Adding Python Clamp Function

Clamp a number between a max and a min.
master
Nate Bohman 5 anni fa
parent
commit
7d6e9145bc
1 ha cambiato i file con 11 aggiunte e 0 eliminazioni
  1. +11
    -0
      python_utils/clamp.py

+ 11
- 0
python_utils/clamp.py Vedi File

@@ -0,0 +1,11 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def clamp(n, minn, maxn):
"""Clamp a number between a max and a min value.

:param n: Number to clamp.
:param minn: Minimum number to allow.
:param maxn: Maximum number to allow.
"""
return max(min(maxn, n), minn)

Loading…
Annulla
Salva