isPositive - return true if x > 0, otherwise false
isPositive
true
x > 0
false
Example: isPositive(-1)
isPositive(-1)
Legal ops:
Let's play with the sign bit: sign(~n) : 1 if n >= 0
sign(~n)
To get rid of the case when n is 0: sign(~n + 1) : 1 if n > 0 or n = MIN_INT
n
sign(~n + 1)
So, we want the case when both functions return 1:
return ((~n & (~n + 1)) >> 31) & 1;