I\'m trying to write a branchless function to return the MAX or MIN of two integers without resorting to if (or ?:). Using the usual technique I can do this easily enough for a
Here's another approach for branchless max and min. What's nice about it is that it doesn't use any bit tricks and you don't have to know anything about the type.
template
inline T imax (T a, T b)
{
return (a > b) * a + (a <= b) * b;
}
template
inline T imin (T a, T b)
{
return (a > b) * b + (a <= b) * a;
}