$f(n) = \begin{cases}-2n,&\text{if }n < 0\\ 2n+1,&\text{if }n\ge 0\end{cases}$
$f^{-1}(n) = \begin{cases}-\frac{n}2,&\text{if }n\text{ is even}\\\\ \frac{n-1}2,&\text{if }n\text{ is odd}\end{cases}$
I would like to know where the $n$ is even and $n$ is odd come from exactly and how to determine the "condition" for similar functions.