From 40e75c79127ffa545040d2d97e6cc7d596bafe9b Mon Sep 17 00:00:00 2001 From: vangel76 Date: Wed, 4 Nov 2026 00:05:58 +0100 Subject: [PATCH] binom/poisson reference test: fail on errors, NaN and non-zero results for zero references (review point) CodeRabbit pointed out that an error or NaN result passed the accuracy test and that a zero reference allowed any finite value (the bound was infinite). Errors now count as infinite error and a zero reference allows 1e-300. Co-Authored-By: Claude Sonnet 5.5 --- crates/functions/src/stat/tests.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/functions/src/stat/tests.rs b/crates/functions/src/stat/tests.rs index f8a8c1890..67e626251 100644 --- a/crates/functions/src/stat/tests.rs +++ b/crates/functions/src/stat/tests.rs @@ -775,7 +775,8 @@ const POISSON_REF: &[(f64, f64, f64, f64)] = &[ ]; fn rel_err(got: Value, want: f64) -> f64 { - let g = got.as_f64().unwrap_or(f64::NAN); + // An error or a non-finite result is the worst possible miss, not a skipped one. + let Some(g) = got.as_f64().filter(|g| g.is_finite()) else { return f64::INFINITY }; if want == 0.0 { g.abs() } else { ((g - want) / want).abs() } } @@ -784,6 +785,10 @@ fn rel_err(got: Value, want: f64) -> f64 { /// most 9e-14 on the grid (the n = 100,000 cumulative cases), 2e-14 for n <= 10,000 away from the /// far tails, 2e-15 on the Excel-sized central cases. The log-gamma code was off by 1.5e-11. fn allowed(want: f64) -> f64 { + // A reference that underflows to 0 must come back as (almost) 0, not as any finite value. + if want == 0.0 { + return 1e-300; + } 1e-13 + 2e-16 * want.abs().ln().abs() }