-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,155
  • 14
  • 29
  • 44

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
  • 7,655
  • 8
  • 57
  • 115
0

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

amaurea
  • 4,811
  • 21
  • 34