Ver código fonte

Adding Python Clamp Function

Clamp a number between a max and a min.
master
Nate Bohman 5 anos atrás
pai
commit
7d6e9145bc
1 arquivos alterados com 11 adições e 0 exclusões
  1. +11
    -0
      python_utils/clamp.py

+ 11
- 0
python_utils/clamp.py Ver arquivo

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

Carregando…
Cancelar
Salvar