If you just want to make sure that the value is not higher or lower than other values, you should use MAX (a, b) and MIN (a, b) ...
float maxValue = 1.0;
float minValue = 0.0;
float myValue = 2.8;
float myValueConstrained = MAX(minValue, MIN(maxValue, myValue));
MIN (a, b) takes the smallest of a and b
MAX (a, b) takes the largest of a and b
Usually I just do this:
float myValueConstrained = MAX(0.0, MIN(1.0, myValue));
source
share