One-Way Inverse My Algebra $2$ teacher stressed the fact that when you find the inverse $g$ of a function $f$, you must not only check that
$$f \circ g=\operatorname{id}$$
but you must also check that
$$g \circ f=\operatorname{id}$$
For example, if 
$$f(x)=x^2$$
then
$$g(x)=\sqrt{x}$$
is not its inverse, because
$$f(g(x))=\sqrt{x^2}=|x|\ne x$$
However, I feel that this is minor... $|x|$ is equal to $x$ half of the time (if $x$ is real) and the other half of the time, it is just $-x$.
Can anyone think of an example of two functions $f$ and $g$ such that
$$f \circ g=\operatorname{id}$$
but, when composed in the other order, the result is something totally wacky that is almost never equal to $\operatorname{id}$?

Let $g$ be $\arctan$ and let $f$ be $\tan$ when defined and $17$ for the rest of the inputs (for $\dfrac{\pi}{2}+k\pi$ for integers $k$). Then $f\circ g=\mathrm{id}_{\mathbb R}$ but $g\circ f(x)=x$ only for $x\in\left(-\dfrac{\pi}{2},\dfrac{\pi}2\right)$.
