Which is the simplest way to check if two integers have same sign? Is there any short bitwise trick to do this?
I'm not really sure I'd consider "bitwise trick" and "simplest" to be synonymous. I see a lot of answers that are assuming signed 32-bit integers (though it would be silly to ask for unsigned); I'm not certain they'd apply to floating-point values.
It seems like the "simplest" check would be to compare how both values compare to 0; this is pretty generic assuming the types can be compared:
bool compare(T left, T right)
{
return (left < 0) == (right < 0);
}
If the signs are opposite, you get false. If the signs are the same, you get true.