I was fooling around by differentiating some functions under the integral sign, and I seem to have stumbled on a problem I don't quite understand. There is another question here which asks something similar at the end, but the answer doesn't address it.
Consider the following integral: $$I = \int_{-\infty}^\infty \frac{\sin(k x)}{x} \text{d}x = \int_{-\infty}^\infty \frac{\sin(u)}{u} \text{d}u = \pi,$$
where I've used the substitution $u=kx$. Clearly, this integral is independent of $k$, and so $$\frac{\text{d}I}{\text{d}k} = 0.$$
However, if I use differentiation under the integral sign:
$$\frac{\text{d}I}{\text{d}k} = \int_{-\infty}^\infty\frac{\partial}{\partial k}\left( \frac{\sin(k x)}{x}\right) \text{d}x = \int_{-\infty}^\infty \cos(k x) \text{d}x,$$
where I have used Leibniz's Integral Rule, since the sinc function in the integral is continuous, and the integral converges. (Are there any assumptions that I'm missing here?) The problem is that this seems to imply that $$\int_{-\infty}^\infty \cos(k x) \text{d}x = 0,$$
which doesn't make sense! (Does it?) I study physics, so I have a habit of being slightly sloppy with mathematics. It wouldn't surprise me that there's some assumption that needs to be satisfied when differentiating under the integral sign that this function does not satisfy, but I can't figure out what it is. Can anyone tell me what I'm doing wrong?
EDIT:
Ok, so I have a slightly better idea of what I'm doing wrong, but I'm still not completely comfortable with it.
$$I = \int_{-\infty}^\infty \frac{\sin(k x)}{x} \text{d}x = \begin{cases} \,\,\pi& \quad k>0 \\-\pi& \quad k<0\end{cases} = \pi \,\, \text{sgn}(k),$$
where $\text{sgn}$ is the signum function. Using the fact that $$\frac{\text{d}}{\text{d}k} \text{sng}(k) = 2 \delta(k),$$ I get that
$$\frac{\text{d}I}{\text{d}k} = 2\pi \delta(k),$$ and so
$$\int_{-\infty}^\infty \cos(kx)\text{d} x = 2\pi \delta(k),$$
which seems to be the real part of the well known relation
$$\int_{-\infty}^\infty e^{i k x} \text{d}x = 2 \pi \delta(k).$$
So it looks like this might make sense if I think in terms of distributions. I'd appreciate any further input, though.