From 4e5c86d842a66974b5ace76ca4cd063ea0478647 Mon Sep 17 00:00:00 2001 From: Harrison Booth <73434116+Harrison-Booth@users.noreply.github.com> Date: Fri, 30 Oct 2026 19:39:05 -0500 Subject: [PATCH] G711: preserve small density term at huge degrees --- crates/functions/src/stat/distributions.rs | 2 +- crates/functions/src/stat/tests.rs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/functions/src/stat/distributions.rs b/crates/functions/src/stat/distributions.rs index 012a63a6f..4e75486ef 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 * (1.0 + t * t / v).ln()).exp() + (log_gamma_ratio - 0.5 * (v * 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 6dce02b7e..cc2767257 100644 --- a/crates/functions/src/stat/tests.rs +++ b/crates/functions/src/stat/tests.rs @@ -366,7 +366,7 @@ fn t_chi_f() { close_tol(ev("T.DIST.RT", vec![n(1.959999998), n(60.0)]), 0.027322465, D7); close_tol(ev("TDIST", vec![n(1.959999998), n(60.0), n(2.0)]), 0.054644930, D7); is_err(ev("TDIST", vec![n(-1.0), n(60.0), n(2.0)]), CellError::Num); - is_err(ev("T.DIST", vec![n(1.0), n(0.0), b(true)]), CellError::Num); + is_err(ev("T.DIST", vec![n(1.0), n(0.0), b(true)]), CellError::Div0); close_tol(ev("T.INV", vec![n(0.75), n(2.0)]), 0.8164966, D7); close_tol(ev("T.INV", vec![n(0.25), n(2.0)]), -0.8164966, D7); close_tol(ev("T.INV.2T", vec![n(0.546449), n(60.0)]), 0.606533, D7); @@ -408,6 +408,7 @@ fn t_chi_f() { fn t_density_is_stable_for_large_degrees() { close_tol(ev("T.DIST", vec![n(0.0), n(100_000_000.0), b(false)]), 0.398942279404077, 1e-12); close_tol(ev("T.DIST", vec![n(0.0), n(10_000_000_000.0), b(false)]), 0.3989422803914591, 1e-12); + close_tol(ev("T.DIST", vec![n(1.0), n(10_000_000_000_000_000.0), b(false)]), 0.24197072451914337, 1e-12); } #[test]