How to calculate Maximum or Minimum of two numbers without using if?

If you let $a$ and $b$ be any two numbers then,

$$\max (a,b) = \frac{1}{2}( a + b + |a-b| )$$.


If $a$ and $b$ are both positive, then $$ \max(a,b) = \lim_{n\to\infty} \left(a^n+b^n\right)^{1/n}. $$


Whether you need an if statement to take an absolute value depends on the format in which your numbers are stored. If you're using IEEE floating point numbers, you can take the absolute value by masking out the sign bit.