Can we Clamp and Clip numbers mathematically? While programming I came up with a the following equation / workflow
clampValue = (value - minValueofRange) / (maxValueofRange - minValueofRange);
clippedValue = min(1, max(0, clampValue));
finalValue = clippedValue * scale;

Now the clipping ultimately causes an if and else in programming. Can we convert it completely to a mathematical equation?
Edit:
max and min are functions in c++ defined like:
int max(int v1, int v2){
    if(v1 > v2) return v1;
    else return v2;
}

Similar for the min() function
 A: Using a piecewise function as in T. Linnell's answer or simply writing something like $\min(1,\max(0,c))$ would be clear and absolutely fine in mathematics.
If you just happen to be curious about how to represent $\min$ and $\max$ in a different way, $\max(a,b)=\dfrac{|a-b|+a+b}{2}$ and $\min(a,b)=\dfrac{a+b-|a-b|}{2}$.
A: I assume that you are after a branchless expression (otherwise you can stick to the $\min/\max$ definition).
I don't think there is anything in the floating-point mathematical functions that can help you. There are indeed built-in functions such as $\min$, $\max$ and $\text{abs}$ that you can use, but you don't know if they are implemented in a branchless way.
If you are looking for "by all means" optimization, you can hack into the floating-point representation and play with the sign bit, which is the most significant one.
For instance, in C, using a union with { int i; float f; }, the expression ~(i >> 31) & i implements the clamping of the negatives, $\max(0, f)$.
A: If you want a functional expansion of the min/max function, use
$$ {\rm MinMax}(0,1,x) = \frac{ |x| - |x+|x|-2|}{4} + \frac{x+2}{4} $$
Or more generally
$$ {\rm MinMax}(x_{min},x_{max},x) = \frac{ |x-x_{min}| - | x+x_{min} + |x-x_{min}|-2 x_{max} |}{4} + \frac{x+2 x_{max}+x_{min}}{4} $$
A: Mathematically, you're after a piecewise function:
$$f(x;a,b) = \begin{cases}0 & x < a\\ \frac{x-a}{b-a} &a\le x \le b\\ 1 &x > b\end{cases}$$
You can then multiply by whatever scalar factor you desire. I don't think there's a simpler way to do it in programming code than how you have. Ultimately, you need two comparisons to achieve the desired behaviour, which your code effectively has in the max and min functions.
A: In sum you can display clipped value as:
$$
clamp = \frac {value - min(A)}{max(A) - min(A)}
$$
$$
max = \frac {\lvert clamp \rvert + clamp}{2}
$$
$$
min = \frac {\lvert 1 - max \rvert + 1 + max}{2}
$$
$$
clip = min; \ final =clip*scale 
$$
$$
final = \frac {\lvert 1 - \frac {\lvert \frac {value - min(A)}{max(A) - min(A)} \rvert + \frac {value - min(A)}{max(A) - min(A)}}{2} \rvert + 1 + \frac {\lvert \frac {value - min(A)}{max(A) - min(A)} \rvert + \frac {value - min(A)}{max(A) - min(A)}}{2}}{2} * scale
$$
or:
$$
scale * \frac{1}{4} * \Biggl(\frac{x}{a - b}- \sqrt{\biggl(\frac{b - x}{a - b} - \frac {\sqrt{ (b - x) ^2}}{\sqrt{(a - b)^2}} + 2\biggr)^2} + \frac {\sqrt{(b - x)^2}}{\sqrt{(a - b)^2}} - \frac {b}{a - b} + 2 \Biggr)
$$
$with\ a = max(A), \ b = min(A)\ and\ A=Range$
