瀏覽代碼

Adding Python Clamp Function

Clamp a number between a max and a min.
master
Nate Bohman 5 年之前
父節點
當前提交
7d6e9145bc
共有 1 個文件被更改,包括 11 次插入0 次删除
  1. +11
    -0
      python_utils/clamp.py

+ 11
- 0
python_utils/clamp.py 查看文件

@@ -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…
取消
儲存