diff --git a/crates/functions/src/stat/distributions.rs b/crates/functions/src/stat/distributions.rs index 4e75486ef..d90999200 100644 --- a/crates/functions/src/stat/distributions.rs +++ b/crates/functions/src/stat/distributions.rs @@ -26,7 +26,7 @@ fn t_pdf(t: f64, v: f64) -> f64 { } else { ln_gamma(z + 0.5) - ln_gamma(z) }; - (log_gamma_ratio - 0.5 * (v * std::f64::consts::PI).ln() - (v + 1.0) / 2.0 * (t * t / v).ln_1p()).exp() + (log_gamma_ratio - 0.5 * (v.ln() + std::f64::consts::PI.ln()) - (v + 1.0) / 2.0 * (t * t / v).ln_1p()).exp() } /// t ≥ 0 with P(T > t) = q, q in (0, 0.5]. diff --git a/crates/functions/src/stat/tests.rs b/crates/functions/src/stat/tests.rs index 2b215afe3..3d3b9ec24 100644 --- a/crates/functions/src/stat/tests.rs +++ b/crates/functions/src/stat/tests.rs @@ -360,6 +360,7 @@ fn normal() { #[test] fn t_chi_f() { + close_tol(ev("T.DIST", vec![n(0.0), n(6e307), b(false)]), 0.3989422804, 1e-10); close_tol(ev("T.DIST", vec![n(60.0), n(1.0), b(true)]), 0.99469533, D7); close_tol(ev("T.DIST", vec![n(8.0), n(3.0), b(false)]), 0.00073691, 1e-5); close_tol(ev("T.DIST.2T", vec![n(1.959999998), n(60.0)]), 0.054644930, D7);