Skip to main content

ln_gamma

Function ln_gamma 

Source
pub fn ln_gamma(x: f64) -> f64
Expand description

The logarithm of the gamma function, $\ln \Gamma(x)$ for $x > 0$, by the Lanczos approximation ($g = 7$, nine coefficients; relative error about $10^{-15}$) and the reflection formula $\Gamma(x)\Gamma(1-x) = \pi / \sin(\pi x)$ below $1/2$.

§Examples

use comnum_math::ln_gamma;
// Γ(10) = 9! = 362 880, Γ(1/2) = √π
assert!((ln_gamma(10.0) - 362_880f64.ln()).abs() < 1e-13);
assert!((ln_gamma(0.5) - std::f64::consts::PI.sqrt().ln()).abs() < 1e-14);