I'm looking for two functions, assuming x is an integer: $$ f(x) = \begin{cases}0&\text{if x is odd}\\1&\text{if x is even}\end{cases} $$ and $$ g(x) = \begin{cases}1&\text{if x is odd}\\ 0&\text{if x is even}\end{cases} $$
For now I went up with the following : $$ f(x) = \frac{\cos(x\pi)+1}{2} $$ and $$ g(x) = -\frac{\cos(x\pi)-1}{2} $$
Is there any better / faster way ?
min(abs x', abs(x'-2)) where x' = x `mod` 2– John Dvorak Dec 20 '14 at 22:10g(x)=abs(x)%2is good enough. For $f(x)$, use1-g(x)or even!g(x)– Thomas Andrews Dec 20 '14 at 22:13