Avoid overflow in t density normalization

This commit is contained in:
Harrison Booth
2026-10-30 20:52:05 -05:00
parent a9bacdca4c
commit ca44a5d68f
2 changed files with 2 additions and 1 deletions
+1 -1
View File
@@ -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].
+1
View File
@@ -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);