Lair Of The Multimedia Guru

2005-11-23

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 @ 07:27

3 Comments »

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

    Comment by Lurchi — 2005-12-07 @ 22:45

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

    Comment by Lurchi — 2005-12-07 @ 22:47

  3. Thanks Lurchi, i updated the Note: …

    Comment by Michael — 2005-12-07 @ 23:49

RSS feed for comments on this post. TrackBack URI

Leave a comment

Powered by WordPress