What is $\arctan(x) + \arctan(y)$

I know $$g(x) = \arctan(x)+\arctan(y) = \arctan\left(\frac{x+y}{1-xy}\right)$$

which follows from the formula for $\tan(x+y)$. But my question is that my book defines it to be domain specific, by which I mean, has different definitions for different domains:

$$g(x) = \begin{cases}\arctan\left(\dfrac{x+y}{1-xy}\right), &xy < 1 \\[1.5ex]
\pi + \arctan\left(\dfrac{x+y}{1-xy}\right), &x>0,\; y>0,\; xy>1 \\[1.5ex]
-\pi + \arctan\left(\dfrac{x+y}{1-xy}\right), &x<0,\; y<0,\; xy > 1\end{cases}$$

Furthermore, When I plot the function $2\arctan(x)$, it turns out that the book definition is correct. I don’t understand how such peculier definition emerges. Thank you.

Solutions Collecting From Web of "What is $\arctan(x) + \arctan(y)$"

Fix, as usual:

$$
-\frac{\pi}{2}<\gamma=\arctan(t)<\frac{\pi}{2}
$$

now we have:
$$
\tan (\gamma)=\tan(\alpha+\beta)=\frac{x+y}{1-xy}=t
$$
and, if $xy>1$ we have the two cases ($x$ and $y$ have the same sign):
$$
x>0, y>0 \rightarrow t<0 \rightarrow \gamma<0\rightarrow \alpha+\beta=\gamma+\pi
$$
$$
x<0, y<0 \rightarrow t>0 \rightarrow \gamma>0\rightarrow \alpha+\beta=\gamma-\pi
$$

I can prove that if $|xy|<1$, that

1) $$-\frac {\pi}{2}<\arctan(x)+\arctan(y)<\frac {\pi}{2}$$

2) $$\arctan(x)+\arctan(y)=\arctan\left(\frac{x+y}{1-xy}\right)$$