There are two int variables: a and b, don’t use “if”, “? :”, “switch” or other judgement statements, find out the biggest one of the two numbers.
// 如果 i >= 0,返回0。否則返回1。在 max() 中被調用。
inline int signof(int i)
{
return unsigned(i) >> (sizeof (int) * 8 - 1);
}
// 返回兩個整型參數中數值較大的參數的值。
int max(int a, int b)
{
int p[2];
p[0] = a;
p[1] = b;
return p[signof(a - b)];
}