If a function $f(x)$ is $2\pi$ periodic, we may calculate its Fourier coefficients $$a_n = \frac{1}{2\pi}\int_0^{2\pi}f(x)e^{inx}dx$$ by numerical integration. However, when $f(x)$ is smooth enough (such as $f(x) = \cos(\cos(x))$) and thus $a_n$ decays fast, the relative error of the calculation will be very big.
I think this is because when doing numerical integration, we are adding some $f(x_k)e^{inx_k}$, which are relatively big, to get a small number $a_n$. Is there any method to avoid this?