I found the AGGREGATE Magic trick for quickly calculating maximum values. The only problem is that this is for integers, and yet I tried some things, I have no idea how to make a version for unsigned integers.
inline int32_t max(int32_t a, int32_t b) { return a - ((ab) & (ab)>>31); }
Any tips?
EDIT
Do not use this because, as others have claimed, it creates undefined behavior. For any modern architecture, can the compiler issue a conditional conditional move return (a > b) ? a : b from return (a > b) ? a : b return (a > b) ? a : b , which will be faster than the corresponding function.
c ++ algorithm bit-manipulation c ++ 11
plasmacel
source share