Simplest way to check if two integers have same sign?

Gerber picture Gerber · Sep 15, 2008 · Viewed 42.6k times · Source

Which is the simplest way to check if two integers have same sign? Is there any short bitwise trick to do this?

Answer

Rik picture Rik · Sep 16, 2008

What's wrong with

return ((x<0) == (y<0));  

?