def clamp(val, lower, upper):
 assert (lower <= upper)
 return min(max(val, lower), upper)

def clamp ( val , lower , upper ) : assert ( lower <= upper ) return min ( max ( val , lower ) , upper )
clamp val to the inclusive range [lower .