Le 4 août 2016 19:59, "Random832" firstname.lastname@example.org a écrit :
def clamp(min_val, value, max_val): return min(max_val, max(value , min_val))
Ideally min and max should themselves be defined in a way that makes that not an issue (or perhaps only an issue for different-signed zero values)
There is a generic sum() and a specific math.fsum() function which is more accurate to sum a list of float.
Maybe before starting to talk about clamp(), we should define new math.fmin() and math.fmax() functions?
A suggest to start to write a short PEP as the math.is_close() PEP since there are subtle issues like NaN (float but also Decimal!) and combinations of numerical types (int, float, complex, Decimal, Fraction, numpy scalars like float16, ...).
Maybe a PEP is not needed, I didn't read carefully the thread to check if there is a consensus or not.
I dislike the idea of modifying min() and max() to add special cases for float NaN and decimal NaN.
Which type do you expect for fmax(int, int)? Should it be int or float?
Should fmax(Decimal, float) raise an error, return a float or return a Decimal?