If you have a harmonic oscillator with damping $D$ (e.g. small angle pendulum)
$$\ddot{\theta}+D\dot{\theta} + \theta=0$$
then the solution I get in the underdamped case ($D^2-4<0$) is: $$\theta=\theta_0e^{-\gamma t}\cos{(\omega t)}$$ where $\gamma=\frac{D}{2}$ and $\omega=\frac{1}{2}\sqrt{4-D^2}$, and $\theta_0$ is the inital angular displacement. We have assumed the inital angular velocity $\dot{\theta}$ is zero.
The solution I get for the critically damped case ($D^2-4=0$) is: $$\theta=\theta_0(1+t)e^{-\gamma t}$$
Fine. Except that they don't match. When $D^2-4=0$, the underdamped case becomes $\theta=\theta_0e^{-\gamma t}$ which is not the same as the critically damped case.
Furthermore, if the pendulum is close to critically damped, the underdamped equation does not seem to be accurate, as shown by this simulation (using 4th order Runge-Kutta):
If the damping is smaller, the underdamped equation is closer to the simulation, but not quite there:
And if there is no damping, the resulting cosine wave is exactly the same as the simulation.
So does this mean the analytic solution for an underdamped pendulum is actually an approximation only valid for small damping, or have I done something wrong?