Find max of 3 integers. Tricky solution
I was looking at a solution online to find the max of 3 integers, x, y and z
The solution is as follows:
result = (x + y + abs(x - y)) / 2;
max = (result + z + abs(result - z)) / 2;
Where is this derived from? It looks like some sort of super-efficient math logic, to avoid using if-else statements. I'd like to understand how it works.