浏览代码

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)

正在加载...
取消
保存