How to integrate $\frac{1}{(1+a\cos x)}$ from $-\pi$ to $\pi$ How to solve the following integration?$$\int_{-\pi}^\pi\frac{1}{1+a \cos x}$$

So, here's how I like to think of proceeding.  
We know the following identities:
$$\sin^2(x/2)=\frac{1-\cos x}{2}$$
$$\cos^2(x/2)=\frac{1+\cos x}{2}$$
Now, the function $1+a\cos u$ can be written as 
$$1+a\cos u=A(1+\cos u)+B(1-\cos u)$$
where $A+B=1$ and $A-B=a$.  Thus, $A=\frac12(1+a)$ and $B=\frac12(1-a)$.
Now, we can write
$$\begin{align}
\frac{1}{1+\cos u}&=\frac{1}{\frac12(1+a)(1+\cos u)+\frac12(1-a)(1-\cos u)}\\\\
&=\frac{1}{(1+a)\cos^2(u/2)+(1-a)\sin^2(u/2)}\\\\
&=\frac{1}{1+a}\frac{\sec^2(u/2)}{1+\frac{1-a}{1+a}\tan^2(u/2)}\\\\
\end{align}$$
To integrate this, we have
$$\begin{align}
\int_{-\pi}^{\pi} \frac{1}{1+\cos u}\,\, du&=\int_{-\pi}^{\pi} \frac{1}{1+a}\frac{\sec^2(u/2)}{1+\frac{1-a}{1+a}\tan^2(u/2)}\,\, du\\\\
\end{align}$$
Case 1:  Assume $|a|<1$
Making the substitution $t=\sqrt{\frac{1-a}{1+a}}\tan(u/2)$ implies that $dt=\frac12 \sqrt{\frac{1-a}{1+a}}\sec^2(u/2)du$, and the limits of integration transform from $(-\pi, \pi)$ to $(-\infty,\infty)$.  Thus, 
$$\begin{align}
\int_{-\pi}^{\pi} \frac{1}{1+\cos u}\,\, du&=2\frac{1}{\sqrt{1-a^2)}}\int_{-\infty}^{\infty} \frac{dt}{1+t^2}\\\\
\end{align}$$
The anti-derivative of $\frac{1}{1+t^2}$ is $\arctan(t)$, which when evaluated between $-\infty$ and $+\infty$ is $\pi$.  
The final result is thus $\frac{2\pi}{\sqrt{1-a^2}}$.
Case 2:  Assume $a>1$
Making the substitution $t=\sqrt{\frac{a-1}{1+a}}\tan(u/2)$ implies that $dt=\frac12 \sqrt{\frac{a-1}{1+a}}\sec^2(u/2)du$, and the limits of integration transform from $(-\pi, \pi)$ to $(-\infty,\infty)$.  Thus, 
$$\begin{align}
\int_{-\pi}^{\pi} \frac{1}{1+\cos u}\,\, du&=2\frac{1}{\sqrt{a^2-1)}}\int_{-\infty}^{\infty} \frac{dt}{1-t^2}\\\\
\end{align}$$
This integral diverges (singularities at $\pm \infty$ and $\pm 1$), unless it is interpreted in a Cauchy Principal Value sense with 
$$\int_{- \infty}^{\infty} \frac{dt}{1-t^2} =\lim_{M \to \infty} \lim_{\epsilon  \to 0} \left(    \int_{-M}^{-1-\epsilon} \frac{dt}{1-t^2} +\int_{-1+\epsilon}^{1-\epsilon} \frac{dt}{1-t^2} +\int_{1+\epsilon}^{M} \frac{dt}{1-t^2} \right)$$
in which case the integral is zero!
Case 3:  Assume that $a<-1$
This case is similar to Case 2 - the integral diverges unless it is interpreted in a Cauchy Principal Value sense for which the result in zero.
Case 4:  $|a| =1$
The integral diverges whether or not it is interpreted in a Cauchy Principal Value sense.
