A mystery of $\int \frac{1}{a^2\cos^2{x}+b^2\sin^2{x}} dx$ I am reading a calculus book.
This book contains the following problem:

Let $a,b>0$.
Find $$\int \frac{1}{a^2\cos^2{x}+b^2\sin^2{x}} dx.$$

The author's answer is

$$\frac{1}{ab}\arctan{(\frac{b}{a}\tan{x})}.$$

This function is not continuous and is not even defined at $\frac{\pi}{2}+n\pi(n\in\mathbb{Z}).$
$\frac{1}{a^2\cos^2{x}+b^2\sin^2{x}}$ is defined on $\mathbb{R}$.
I think primitive functions are continuous but this function is not continuous.
Why?
 A: As a function of $x$, $f(x)=\frac1{ab}\arctan(b \tan(x)/a)$ is continuous for all $x\ne \frac\pi2 +n\pi$.  Moreover, $f(x)$ has removeable discontinuities at $x=\frac\pi2 +n\pi$.
We can write, therefore
$$f(x)=\begin{cases}\frac1{ab}\arctan(b \tan(x)/a)&, x\in (\pi/2 +n\pi, \pi/2 +(n+1)\pi)\\\\
\frac{\pi/2}{ab}&,x=\pi/2+(n+1)\pi, \\\\
-\frac{\pi/2}{ab}&,x=\pi/2+n\pi,\\\\
\end{cases}$$
In fact, $f(x)$ is differentiable on the open interval $(\pi/2+n\pi,\pi/2+(n+1)\pi)$ and has left-side and right-side derivatives at the end points.
A: An overall continuous anti-derivative function valid for $x\in \mathbb{R} $ is instead
$$\int \frac{1}{a^2\cos^2{x}+b^2\sin^2{x}} dx
= \frac{1}{ab}\arctan{\left(\frac{b}{a}\tan{x}\right)} +\pi \left[{\frac x\pi+\frac12\text{sgn}(x)}\right]+C
$$

where $[]$ represents the integer function.
A: When you divide the numerator and denominator of $\frac{1}{a^2\cos^2{x}+b^2\sin^2{x}}$ by $cos^2{x}$ to integrate it with respect to $x$, you made a tacit assumption that $cos{x}\neq 0$ i.e $x$ does not belong to odd multiple of $\pi/2$.
Therefore, the primitive function $\frac{1}{ab}\arctan{(\frac{b}{a}\tan{x})}$ need not be derivable or continuous or defined at $x= \frac{\pi}{2}+n\pi (n\in\mathbb{Z})$
