Which is the simplest way to check if two integers have same sign? Is there any short bitwise trick to do this?
branchless C version:
int sameSign(int a, int b) { return ~(a^b) & (1<<(sizeof(int)*8-1)); }
C++ template for integer types:
template T sameSign(T a, T b) { return ~(a^b) & (1<<(sizeof(T)*8-1)); }