I'm trying to calculate the inverse of the function: $$y= \tan \left( \cos^{-1} \frac{x}{x+2} \right) $$
In my opinion it is $y= \frac{2 \cos ( \tan^{-1} x )}{1-\cos ( \tan^{-1} x )} $ but in my book it is reported : $f(x)\begin{cases} -2\left( \frac{\sqrt{1+x^2}-1}{x^2} \right) & x < 0\\ -1 & x = 0\\2 \left( \frac{\sqrt{1+x^2}+1}{x^2} \right) & x>0 \end{cases}$
Can someone explain me the passages?


Hint $$y= \tan\big[ \arccos(f(x)) \big]=\frac{\sqrt{1-f(x)^2}}{f(x)}$$ could help you.