What happened to Math.Max ?
You can make an equivalent without a branch using bitwise operations:
r = x ^ ((x ^ y) & -(x < y)); // == max(x, y)
If you replace zero, it will fall on:
r = (y & -(0 < y)); // == max(0, y)
(Source: this list of bitwise tricks.)
If the branches were extremely expensive on your platform, it might have cost in some kind of inner loop, but it is rather obscure, and not something that I would like to meet outside of an extremely time-sensitive function.
Tim sylvester
source share