-2

The following macro is to determine if two numbers have the same sign, is for 2's complement number representation.

#define SAME_SIGNS( a, b )  (((long) ((unsigned long) a ^ (unsigned long) b)) >= 0 )

Can anyone suggest a javascript equivalent function?

Lee Taylor
  • 7,761
  • 16
  • 33
  • 49

2 Answers2

1
(a < 0 === b < 0)

or

(a * b > 0) // If one of a or b is 0, can't tell.

or

(a < 0 && b < 0 || a > 0 && b > 0)

true -> same, else different

Virus721
  • 8,061
  • 12
  • 67
  • 123
0

It won't be exactly the same, but how about something like !(a*b<0)?

amaurea
  • 4,950
  • 26
  • 35