# Clarifying the residue theorem to compute a real trigonometric integral where denominator vanishes

I was asked to solve this exercise in class where we are dealing with the residue theorem and its use for computing real trigonometric integrals on the real axis. We are asked to compute:

$$I = \int_{0}^{2\pi} \frac{1-\cos(nx)}{1-\cos{x}}dx$$

for a natural $$n$$. When I tried the naive way in class to substitute:

$$\cos(z) = \frac{e^{iz}+e^{-iz}}{2}$$

and perform a contour complex integral on the unit circle, my professor immediately cut my off saying the denominator vanishes and that I was supposed to use a contour that "works around" or "goes around" the problematic points where the denominator vanishes, at $$0, 2\pi$$. But here is my question: the limit of the integrated function at these points is finite and thus one can say these are removable singularities, but my teacher insists on using the modified contour to work around those points, why is that? Can someone please show me how to compute this properly? Why isn't a simple substitution on the unit circle correct? My teacher also said the same type of workaround was needed to compute:

$$\int_{-\infty}^{\infty} \frac{\sin(x)}{x} dx$$

but here also $$x = 0$$ appears to be a removable singularity, so in both cases, I am lost why the regular contour is incorrect because of the vanishing denominator. I appreciate all help.