Many algorithms require to compute (-1)^n (both integer), usually as a factor in a series. That is, a factor that is -1 for odd n and 1 fo
(-1)^n
-1
1
What about
(1 - (n%2)) - (n%2)
n%2 most likely will be computed only once
n%2
UPDATE
Actually, simplest and most correct way would be using table
const int res[] {-1, 1, -1}; return res[n%2 + 1];