The sign function returns -1 if x is negative and 1 if x is positive. The transformation, $\frac{|x|}{2x}+\frac{1}{2}$, will return 0 if x is negative and 1 if it is positive.

Therefore, test if either a-b is positive or if b-a is positive. If a-b is positive, then the transformed sign function will return 1 and multiply by a; the other side will return 0, so the overall expression is a. It becomes b if b-a is positive.

Weregoose's is a simplification:

(1)
\begin{align} b\left(\frac{|b-a|}{2(b-a)}+\frac{1}{2}\right) + a\left(\frac{|a-b|}{2(a-b)}+\frac{1}{2}\right) \\ \frac{a|a-b|}{2(a-b)}+\frac{a}{2}-\frac{b|a-b|}{2(a-b)}+\frac{b}{2} \\ \frac{1}{2}\left(a+b+\frac{a|a-b|-b|a-b|}{a-b}\right) \\ \frac{1}{2}\left(a+b+\frac{(a-b)|a-b|}{a-b}\right) \\ \frac{1}{2}\left(a+b+|a-b|\right) \\ \end{align}

I recommend learning the sign function. I've used it plenty of times when making algorithms in other languages mainly because other languages do not count `a(a>b)+b(b≥a)` as a legal statement.