How do I programmatically return the maximum of two integers without using any comparison operators and without using if, else, etc?
In the math world:
max(a+b) = ( (a+b) + |(a-b)| ) / 2
min(a-b) = ( (a+b) - |(a-b)| ) / 2
Apart from being mathematically correct it is not making assumptions about the bit size as shifting operations need to do.
|x| stands for the absolute value of x.
You are right, the absolute value was forgotten. This should be valid for all a, b positive or negative