Joels answer made me think a bit and I believe I found an interesting solution for $f(x)$ : $ f(x) = \begin{cases} ix & \text{if } Im(x) = 0 \\\ \cos(ix) & \text{if } Re(x) = 0 \end{cases}$ It is of course a bit of a trick (reminds me of [Wick Rotation][1]), but I it works for all $x\ \epsilon\ R$, because $f(f(x)) = \cos(i(ix))=\cos(-x) = \cos(x)$ [1]: http://en.wikipedia.org/wiki/Wick_rotation