Lair Of The Multimedia Guru

November 23, 2005

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

Filed under: Optimization — Michael @ 7:27

3 Comments »

  1. max(a,b) ≤ a|b

    Comment by Lurchi — December 7, 2005 @ 22:45

  2. max(a,b) ≤ a|b < 2 * max(a,b)

    Comment by Lurchi — December 7, 2005 @ 22:47

  3. Thanks Lurchi, i updated the Note: …

    Comment by Michael — December 7, 2005 @ 23:49

RSS feed for comments on this post. TrackBack URI

Leave a comment

Powered by WordPress