Fast approximate max of 2 integers
Maybe you are lucky and your cpu instructon set has a fast maximum_of_2_integers instruction, but more likely you wont be so lucky, in that case a simple bitwise OR might be worth a thought.
Note: max(a,b) ≤ a|b < 2 * max(a,b)
This approximation is surprissingly more usefull then it seems at first
max(a,b) ≤ a|b
Comment by Lurchi — 2005-12-07 @ 22:45
max(a,b) ≤ a|b < 2 * max(a,b)
Comment by Lurchi — 2005-12-07 @ 22:47
Thanks Lurchi, i updated the Note: …
Comment by Michael — 2005-12-07 @ 23:49