How accurate is Stirling’s approximation?

The question whether an approximation is good should not be asked in isolation, because the answer depends on the purpose. For example, \(\mathrm{e}^x \approx 1 + x\) works well for small (positive) \(x\). How small? If we want to keep the relative error below 10%, \(x \lt 0.5\) will do fine. But if we need more precision, the range gets narrower, e.g., \(x \lt 0.15\) if the tolerance is smaller than 1%.

ex vs. 1 + x

ex vs. 1 + x

But Stirling’s formula—which gives an approximate value for factorials: \(n! \sim \sqrt{2 \pi n} \left( \frac{n}{\mathrm{e}} \right)^n\) for \(n \gg 1\)—works well even for small integers.

The factorial (the gamma function) vs. Stirling’s approximation

The factorial (the gamma function) vs. Stirling’s approximation

For \(x = 10\) the relative error is less than 1%, for \(x = 100\) the relative error is less than 0.1%, and so on.

The relative error of Stirling’s approximation

The relative error of Stirling’s approximation