Evaluate $\int_0^{2\pi}\frac{1}{1 + A\sin(\theta) + B\cos(\theta)}\, \mathrm{d}\theta \ \text{ for }\ A,B <<1$ I need to evaluate the definite integral $$\int_0^{2\pi}\frac{1}{1 + A\sin(\theta) + B\cos(\theta)}\, \mathrm{d}\theta  \ \text{    for various}\ A,B \text{; with}\ A,B<<1.$$
Wolfram Alpha provides the following indefinite general solution:-
$$\int \frac{1}{1 + A\sin(\theta) + B\cos(\theta)}\, \mathrm{d}\theta =  -(2/K) \tanh^{-1} ( \frac{A-(B-1)\tan(\theta/2)}{K}) $$
where $K = \sqrt{A^2 + B^2 -1}$.
But I am having trouble checking it for the simple case when $A=B=0$ when I would expect the answer to be given by:-
$$\int_0^{2\pi}\frac{1}{1 + 0 + 0}\, \mathrm{d}\theta = 2\pi.$$
I have approached the Wolfram Alpha solution thus:-
$$ -(2/K) \tanh^{-1} ( \frac{\tan(2\pi/2)}{K}) +(2/K) \tanh^{-1} ( \frac{\tan(0/2)}{K}) $$
$$ -(2/K) \tanh^{-1} ( \frac{\tan(\pi)}{K}) +(2/K) \tanh^{-1} ( \frac{\tan(0)}{K}) $$
$$ -(2/K) \tanh^{-1} ( \frac{0}{K}) +(2/K) \tanh^{-1} ( \frac{0}{K}) $$
which gives the result of zero.  
I presume this error comes from trying to integrate across the range $0, 2\pi$ where the $\tan$ function has singularities at $\pi/2$ and $3\pi/2$.
However when I try and break the integration into the three continuous ranges $0,\pi/2$ and $\pi/2,3\pi/2$ and $3\pi/2,2\pi$ I am still getting a result of zero thus:-
$$ -(2/K) \tanh^{-1} ( \frac{\tan(2\pi/2)}{K}) +(2/K) \tanh^{-1} ( \frac{\tan(3\pi/4)}{K}) + $$
$$ -(2/K) \tanh^{-1} ( \frac{\tan(3\pi/4)}{K}) +(2/K) \tanh^{-1} ( \frac{\tan(\pi/4)}{K}) +$$
$$ -(2/K) \tanh^{-1} ( \frac{\tan(\pi/4)}{K}) +(2/K) \tanh^{-1} ( \frac{\tan(0)}{K}) $$
leading to 
$$ -(2/K) \tanh^{-1} ( \frac{0}{K}) +(2/K) \tanh^{-1} ( \frac{-1}{K}) + $$
$$ -(2/K) \tanh^{-1} ( \frac{-1}{K}) +(2/K) \tanh^{-1} ( \frac{1}{K}) +$$
$$ -(2/K) \tanh^{-1} ( \frac{1}{K}) +(2/K) \tanh^{-1} ( \frac{0}{K}) $$
which gives the same result of zero.
I would be grateful if somebody could tell me where I am going wrong here?

EDIT 1: I have accepted the solution provided kindly by Dr. MV.
I have posted a related question which seeks to understand where my original evaluation of the definite integrand goes wrong.

EDIT 2: In the related question  comments from user mickep pointed out that the wrong partitions had been used in the original evaluation. Using the correct partitions ($0...\pi$) and ($\pi...2\pi$) leads to the correct answer, for $A=B=0$, of $2\pi$ (as described in my self-answer to that same question).

EDIT 3: It was pointed out by user mickep in comments to the related question that the Wolfram Alpha solution 
$$ -\left(\frac{2}{K1}\right) {\arctan}h \left( \frac{A-(B-1)\tan(\theta/2)}{K1}\right) $$
where $K1= \sqrt{A^2 + B^2 -1}$.
is not as friendly as an alternative solution (reported by user mickep) which is:
$$ +\left(\frac{2}{K2}\right) \arctan  \left( \frac{A+(1-B)\tan(\theta/2)}{K2}\right) $$
where $K2 = \sqrt{1 - A^2 - B^2}$.
 A: Note that the integral of interest fails to converge if $\sqrt{A^2+B^2}\ge 1$.  So, we restrict $A$ and $B$ such that $\sqrt{A^2+B^2}< 1$.
Then, we can write
$$\begin{align}
\int_0^{2\pi}\frac{1}{1+A\sin(\theta)+B\cos(\theta)}\,d\theta&=\int_0^{2\pi}\frac{1}{1+\sqrt{A^2+B^2} \cos(\theta-\arctan(A/B)}\,d\theta\\\\
&=\int_{-\arctan(A/B)}^{2\pi-\arctan(A/B)}\frac{1}{1+\sqrt{A^2+B^2} \cos(\theta)}\,d\theta\\\\
&=2\int_{0}^{\pi}\frac{1}{1+\sqrt{A^2+B^2} \cos(\theta)}\,d\theta\tag1
\end{align}$$
where we exploited both the $2\pi$-periodicity and the evenness of the cosine function.
Next, we enforce the Weierstrass Substitution,  $ t=\tan(\theta/2)$, in $(1)$ to obtain
$$\begin{align}
\int_0^{2\pi}\frac{1}{1+A\sin(\theta)+B\cos(\theta)}\,d\theta&=4\int_0^\infty \frac{1}{(1+\sqrt{A^2+B^2})+(1-\sqrt{A^2+B^2})t^2}\,dt\\\\
&=\frac{4}{1-\sqrt{A^2+B^2}}\int_0^\infty \frac{1}{\frac{1+\sqrt{A^2+B^2}}{1-\sqrt{A^2+B^2}}+t^2}\,dt \tag 2\\\\
&=\frac{4}{1-\sqrt{A^2+B^2}} \left.\left(\frac{\arctan\left(\frac{\sqrt{1-\sqrt{A^2+B^2}}}{\sqrt{1+\sqrt{A^2+B^2}}}t\right)}{\sqrt{\frac{1+\sqrt{A^2+B^2}}{1-\sqrt{A^2+B^2}}}}\right)\right|_{0}^{\infty}  \tag 3\\\\
&=\frac{2\pi}{\sqrt{1-A^2-B^2}}  \tag 4
\end{align}$$

Note that we could have written $(2)$ as 
$$\begin{align}
\frac{4}{1-\sqrt{A^2+B^2}}\int_0^\infty \frac{1}{\frac{1+\sqrt{A^2+B^2}}{1-\sqrt{A^2+B^2}}+t^2}\,dt&=\frac{4}{1-\sqrt{A^2+B^2}}\int_0^\infty \frac{1}{t^2-\frac{\sqrt{A^2+B^2}+1}{\sqrt{A^2+B^2}-1}}\,dt\\\\
&=\frac{4}{\sqrt{A^2+B^2}-1}\left.\left( \frac{\text{arctanh}\left(\sqrt{\frac{\sqrt{A^2+B^2}-1}{\sqrt{A^2+B^2}+1}}t\right)}{\sqrt{\frac{\sqrt{A^2+B^2}+1}{\sqrt{A^2+B^2}-1}}}\right)\right|_{0}^\infty\\\\
&=\frac{4}{\sqrt{A^2+B^2}-1}\,\left(\frac{i\pi/2}{\sqrt{\frac{\sqrt{A^2+B^2}+1}{\sqrt{A^2+B^2}-1}}}\right)\\\\
&=\frac{2\pi}{\sqrt{1-A^2-B^2}}
\end{align}$$
as expected!
A: When one of $A$ and $B$ is non-zero, then one way to figure this out for yourself is to put 
$$A \colon= r \cos \beta \ \mbox{ and } \ B \colon= r \sin \beta,$$
where 
$$r = \sqrt{A^2 + B^2} \ \mbox{ and } \ B \tan \beta = A.$$ 
Then 
$$ 
\begin{align}
\int_0^{2\pi} \frac{1}{1+ A \sin \theta + B \cos \theta } \mathrm{d} \theta &= \int_0^{2\pi} \frac{1}{1+r\sin(\beta + \theta) } \mathrm{d} \theta.
\end{align}
$$
Can you take it from here?
As one trick, you can put 
$$z = \tan \frac{\beta + \theta}{2}.$$
Then $$\sin (\beta+\theta) = \frac{2z}{1+z^2} \ \mbox{ and } \ \mathrm{d} \theta = \frac{2 \mathrm{d} z}{1+z^2}.$$
When $\theta = 0$, $z= \tan \beta/2$, and when $\theta = 2\pi$, $z= \tan \left( \pi+ \beta/2 \right) = \tan \beta/2$. 
So, 
$$ 
\begin{align}
\int_0^{2\pi} \frac{1}{1+ A \sin \theta + B \cos \theta } \mathrm{d} \theta &= \int_0^{2\pi} \frac{1}{1+r\sin(\beta + \theta) } \mathrm{d} \theta  \\
&= 2 \int_{\tan \beta/2}^{\tan \beta/2} \frac{1}{1+2rz+z^2} \mathrm{d} \theta \\ 
&= 0
\end{align}
$$
For $A = B=0$, the answer is $2\pi$, as you've correctly found out. 
A: A solution through complex analysis is missing, so I will provide one. By De Moivre's identities the given integral equals
$$ \int_{0}^{2\pi}\frac{e^{i\theta} d\theta} {e^{i\theta}+ \frac{A-Bi}{2}e^{2i\theta}+\frac{A+Bi}{2}}=-i\oint_{|z|=1}\frac{dz}{\frac{A-Bi}{2}z^2+z+\frac{A+Bi}{2}}$$
and that is $2\pi$ times the sum of the residues of the function $\frac{1}{\frac{A-Bi}{2}z^2+z+\frac{A+Bi}{2}}$ at its poles inside the unit circle. The poles lies at $\frac{-1\pm\sqrt{1-A^2-B^2}}{A-iB}$ and the computation is straightforward.
