46045-syslab/util.py

6 lines
111 B
Python

def clamp(a, x, b):
"""
Restrict x to lie in the range [a, b]
"""
return max(a, min(x, b))