3 ms·
>https://graphics.stanford.edu/~seander/bithacks.html#IntegerMinOrMax https://graphics.stanford.edu/~seander/bithacks.html#Integer... The quick and dirty versi
by jhallenworld 10y ago
>https://graphics.stanford.edu/~seander/bithacks.html#IntegerMinOrMax https://graphics.stanford.edu/~seander/bithacks.html#Integer...
The quick and dirty version is still useful (portable, works for all values) for the case of 1/2 word size unsigned versions of min and max:
unsigned max(unsigned short a, unsigned short b)
{
unsigned q = a - b;
unsigned r = ((~q) >> 16);
return r + b;
}
- yitchelle 10y agoDoes the right shift limits this to certain word sizes?