Skip to main content

stirlerr

Function stirlerr 

Source
pub fn stirlerr<P, E, V>(n: V) -> V
where P: Policy, E: FloatElement, V: FloatVector<Element = E> + SpecializedSpecialMath<E>,
Expand description

Stirling’s error $\mathrm{stirlerr}(n) = \ln n! - \left[(n + \tfrac12)\ln n - n + \tfrac12 \ln 2\pi\right]$, for n >= STIRLERR_MIN, by the Bernoulli series

\frac{1}{12n} - \frac{1}{360n^3} + \frac{1}{1260n^5} - \frac{1}{1680n^7} + \frac{1}{1188n^9} - \dots

with stirlerr_terms terms. Cost is a reciprocal and a short Horner ladder. Below STIRLERR_MIN the series does not converge to double precision (see there); this function does not check, it just returns the truncated series.

Last built: 2026-09-08 21:35:55 UTC