diff --git a/crates/functions/src/stat/distributions.rs b/crates/functions/src/stat/distributions.rs index 40e7d5223..cb2f0398a 100644 --- a/crates/functions/src/stat/distributions.rs +++ b/crates/functions/src/stat/distributions.rs @@ -173,13 +173,7 @@ fn df_arg(a: &[Arg], i: usize) -> R { pub(super) fn t_dist(a: &[Arg], _: C) -> R { let x = num(a, 0)?; - let v = num(a, 1)?.trunc(); - if v == 0.0 { - return Err(CellError::Div0); - } - if v < 1.0 { - return Err(CellError::Num); - } + let v = df_arg(a, 1)?; let cum = boolean(a, 2)?; num_val(if cum { t_cdf(x, v) } else { t_pdf(x, v) }) } diff --git a/crates/functions/src/stat/tests.rs b/crates/functions/src/stat/tests.rs index a5bb21f9b..86d9393dd 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::Div0); + is_err(ev("T.DIST", vec![n(1.0), n(0.0), b(true)]), CellError::Num); 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); @@ -405,10 +405,10 @@ fn t_chi_f() { } #[test] -fn t_dist_degrees_truncating_to_zero_return_div0() { +fn t_dist_degrees_truncating_below_one_return_num() { for df in [0.0, 0.9, -0.1] { - is_err(ev("T.DIST", vec![n(0.0), n(df), b(false)]), CellError::Div0); - is_err(ev("T.DIST", vec![n(0.0), n(df), b(true)]), CellError::Div0); + is_err(ev("T.DIST", vec![n(0.0), n(df), b(false)]), CellError::Num); + is_err(ev("T.DIST", vec![n(0.0), n(df), b(true)]), CellError::Num); } is_err(ev("T.DIST", vec![n(0.0), n(-1.0), b(false)]), CellError::Num); close_tol(ev("T.DIST", vec![n(0.0), n(1.99), b(false)]), 1.0 / std::f64::consts::PI, 1e-15);