Evaluate $\left[ -(2/K) \tanh^{-1} ( \frac{A-(B-1)\tan(\theta/2)}{K}) \right]_0^{2\pi}$ where $K = \sqrt{A^2 + B^2 -1}$ and $A^2 + B^2 << 1$. I am having difficulty in evaluating the following integrand: 
$$\left[ -(2/K) \tanh^{-1} ( \frac{A-(B-1)\tan(\theta/2)}{K})
\right]_0^{2\pi}$$ 
where $K = \sqrt{A^2 + B^2 -1}$ and   $A^2 + B^2 << 1$.
=================================================================
To  evaluate the indefinite integral $I$ $$I = \int \frac{1}{1 + A\sin(\theta) + B\cos(\theta)}\, \mathrm{d}\theta \ \text{    for various}\ A,B <<1.$$
Wolfram Alpha provides the following solution:-
$$I= -(2/K) \tanh^{-1} ( \frac{A-(B-1)\tan(\theta/2)}{K}) $$
where $K = \sqrt{A^2 + B^2 -1}$.
In the simple case when $A=B=0$ the definite integral over the range $0...2\pi$ should obviously be given by:-
$$I_{A=B=0}=\int_0^{2\pi}\frac{1}{1 + 0 + 0}\, \mathrm{d}\theta = 2\pi.$$
This specific result has been confirmed by the restricted ( for $A^2+B^2<1$ ) Definite Solution 
$$I=\int_0^{2\pi}\frac{1}{1 + A\cos(\theta) + B\sin(\theta)}\, \mathrm{d}\theta = 2\pi.$$ 
developed by Dr. MV in his answer to my previous question.
However I would like to know where my evaluation of the integrand is going wrong as I will need in future to apply a similar approach to other, more complex integrands for which I dont yet have Definite Solutions.

We might (naively) approach the Wolfram Alpha solution in the following way, noting that when $A=B=0$ so $K=i$, :-
$$I_{A=B=0}= \left[ -(2/i) \tanh^{-1} ( \frac{\tan(\theta/2)}{i}) \right]_0^{\infty}$$
$$= -(2/i) \tanh^{-1} ( \frac{\tan(2\pi/2)}{i}) +(2/i) \tanh^{-1} ( \frac{\tan(0/2)}{i}) $$
$$ = -(2/i) \tanh^{-1} ( \frac{\tan(\pi)}{i}) +(2/i) \tanh^{-1} ( \frac{\tan(0)}{i}) $$
$$ = -(2/i) \tanh^{-1} ( \frac{0}{i}) +(2/i) \tanh^{-1} ( \frac{0}{i}) $$
$$ = 0.$$
but this is clearly incorrect.  I presume the 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$.

So let us 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$ thus:-
$$I_{A=B=0}=$$
$$ -(2/i) \tanh^{-1} ( \frac{\tan(2\pi/2)}{i}) - -(2/i) \tanh^{-1} ( \frac{\tan(3\pi/4)}{i}) + $$
$$ -(2/i) \tanh^{-1} ( \frac{\tan(3\pi/4)}{i}) - - (2/i) \tanh^{-1} ( \frac{\tan(\pi/4)}{i}) +$$
$$ -(2/i) \tanh^{-1} ( \frac{\tan(\pi/4)}{i}) - - (2/i) \tanh^{-1} ( \frac{\tan(0)}{i}) $$
leading to 
$$I_{A=B=0}=$$
$$ -(2/i) \tanh^{-1} ( \frac{0}{i}) +(2/i) \tanh^{-1} ( \frac{-1}{i}) + $$
$$ -(2/i) \tanh^{-1} ( \frac{-1}{i}) +(2/i) \tanh^{-1} ( \frac{1}{i}) +$$
$$ -(2/i) \tanh^{-1} ( \frac{1}{i}) +(2/i) \tanh^{-1} ( \frac{0}{i}) $$
Now 
$tanh^{-1}\frac{0}{i} = 0$,  $tanh^{-1}\frac{-1}{i} = \frac{i\pi}{4}$,   and $tanh^{-1}\frac{1}{i} = \frac{-i\pi}{4}$
and so
$$I_{A=B=0}=$$
$$ -(2/i) 0 +(2/i) \frac{i\pi}{4} + $$
$$ -(2/i) \frac{i\pi}{4}+(2/i) \frac{-i\pi}{4} +  $$
$$ -(2/i) \frac{-i\pi}{4}+(2/i) 0    $$
then 
$$I_{A=B=0}= +(2/i) \frac{i\pi}{4} -(2/i) \frac{i\pi}{4}+(2/i) \frac{-i\pi}{4} -(2/i) \frac{-i\pi}{4}  $$
$$I_{A=B=0}=  \frac{2\pi}{4} -\frac{2\pi}{4} - \frac{2\pi}{4} + \frac{2\pi}{4}  $$
$$I_{A=B=0}= 0$$.
So we still get the wrong answer.  Clearly the right answer ($2 \pi$) could be obtained if all the minus signs were converted into plus signs, but I cant't find justification for doing that, as yet.
Any suggestions welcomed!

Following comments by user mickep let us look at correcting the partitions used...
So, to avoid operating across the singularity at $\frac{\pi}{2}$, let us break the integration into the two continuous ranges $0...\pi$ and $\pi...2\pi$ thus:-
$$I_{A=B=0}=$$
$$ -\left(\frac{2}{i}\right) \tanh^{-1} \left( \frac{\tan\left(2\pi/2\right)}{i}\right) - -\left(\frac{2}{i}\right) \tanh^{-1} \left( \frac{\tan\left(\pi/2\right)}{i}\right) + $$
$$ -\left(\frac{2}{i}\right) \tanh^{-1} \left( \frac{\tan\left(\pi/2\right)}{i}\right) - - \left(\frac{2}{i}\right) \tanh^{-1} \left( \frac{\tan\left(0\right)}{i}\right) +$$
leading to 
$$I_{A=B=0}=$$
$$ -\left(\frac{2}{i}\right) \tanh^{-1} \left( \frac{0}{i}\right) +\left(\frac{2}{i}\right) \tanh^{-1} \left( \frac{-\infty}{i}\right)  -\left(\frac{2}{i}\right) \tanh^{-1} \left( \frac{+\infty}{i}\right) +\left(\frac{2}{i}\right) \tanh^{-1} \left( \frac{0}{i}\right) $$
Now 
$tanh^{-1}\left(\frac{0}{i}\right) = 0$,  $tanh^{-1}\left(\frac{-\infty}{i}\right) = \frac{i\pi}{2} $,   and $tanh^{-1}\left(\frac{\infty}{i}\right) = \frac{-i\pi}{2} $
and so
$$I_{A=B=0} = 0 +\left(\frac{2}{i}\right) \frac{i\pi}{2} -\left(\frac{2}{i}\right) \frac{-i\pi}{2} + 0 $$
$$I_{A=B=0} = \pi --\pi $$
$$I_{A=B=0} = 2\pi . $$
which is the expected answer.
