diff --git a/crates/functions/src/stat/distributions.rs b/crates/functions/src/stat/distributions.rs index 9bd519066..e3521592e 100644 --- a/crates/functions/src/stat/distributions.rs +++ b/crates/functions/src/stat/distributions.rs @@ -186,8 +186,14 @@ fn df_arg(a: &[Arg], i: usize) -> R { pub(super) fn t_dist(a: &[Arg], _: C) -> R { let x = num(a, 0)?; - let v = df_arg(a, 1)?; + let v = num(a, 1)?.trunc(); let cum = boolean(a, 2)?; + if v == 0.0 { + return Err(if cum { CellError::Num } else { CellError::Div0 }); + } + if v < 0.0 { + return Err(CellError::Num); + } 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 3e229262e..ee7639d6d 100644 --- a/crates/functions/src/stat/tests.rs +++ b/crates/functions/src/stat/tests.rs @@ -418,6 +418,17 @@ fn f_distributions_accept_ten_billion_degrees() { is_err(ev("F.DIST.RT", vec![n(0.0), n(1.0), n(10_000_000_001.0)]), CellError::Num); } +#[test] +fn t_dist_zero_degrees_error_depends_on_mode() { + 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::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); + close_tol(ev("T.DIST", vec![n(0.0), n(1.0), b(false)]), 1.0 / std::f64::consts::PI, 1e-15); +} + #[test] fn binom_inv_huge_trials_returns() { // Above 2^53 neighbouring f64 values are more than 1 apart; the bisection must still end. diff --git a/docs/function-parity.md b/docs/function-parity.md index b92e3bd64..90d8344a4 100644 --- a/docs/function-parity.md +++ b/docs/function-parity.md @@ -1,6 +1,6 @@ # Function parity: worksheet functions and formulas -> **Last reviewed:** 2026-10-31 · **Last updated:** 2026-10-31 · **Change:** minor (F distribution functions accept degrees of freedom through 10 billion, and the extreme numerator-degree inverse uses a stable gamma-tail limit; earlier: DOLLAR keeps the negative layout when a negative input rounds to zero at nonnegative precision; negative precision that rounds to zero retains the positive layout, as measured in Windows Excel 16.0 build 20527, LCID 1033; earlier: ECMA.CEILING listed with USDOLLAR as not on Microsoft's list; IMSQRT reproduces the stray real part Excel gives for negative reals, and the other IM* differences from Excel are listed; the LAMBDA row lists the recursion limit and its `#NUM!`, and the error a defined name holding an error gives when called; number text with accounting parentheses coerces like Excel 365; INDEX with one index on a 2-D reference is #REF! as in Excel; SUBTOTAL and AGGREGATE cap the cells they visit, #2175) · **Target:** Microsoft Excel (Microsoft 365), Excel for Mac 16.113.4 +> **Last reviewed:** 2026-10-31 · **Last updated:** 2026-10-31 · **Change:** minor (T.DIST gives `#DIV/0!` for density mode and `#NUM!` for cumulative mode when truncated degrees of freedom are zero; earlier: F distribution functions accept degrees of freedom through 10 billion, and the extreme numerator-degree inverse uses a stable gamma-tail limit; earlier: ECMA.CEILING listed with USDOLLAR as not on Microsoft's list; IMSQRT reproduces the stray real part Excel gives for negative reals, and the other IM* differences from Excel are listed; the LAMBDA row lists the recursion limit and its `#NUM!`, and the error a defined name holding an error gives when called; number text with accounting parentheses coerces like Excel 365; INDEX with one index on a 2-D reference is #REF! as in Excel; SUBTOTAL and AGGREGATE cap the cells they visit, #2175) · **Target:** Microsoft Excel (Microsoft 365), Excel for Mac 16.113.4 Excel's worksheet functions, category by category, against GridCraft's function library. Part of [target-app-parity.md](target-app-parity.md); gaps feed [gaps.md](gaps.md). @@ -133,6 +133,7 @@ workbooks; results checked in as data, not Excel files) and fixing what it finds | 2026-10-31 | minor | FIXED accepts output through 255 characters; DOLLAR accepts output through 254. Windows Excel 16.0 build 20527 (LCID 1033) confirmed the distinct cutoffs with grouped and ungrouped values, signs, currency layout and decimal places | | 2026-10-31 | minor | DOLLAR uses the input sign for negative amounts that round to zero at nonnegative decimal places (`DOLLAR(-0.0001,0)` is `($0)`); when negative decimal places round to zero, Excel returns `$0`. Exact zero and negative zero stay unsigned; FIXED still returns `0` for `FIXED(-0.0001,0)` | | 2026-10-31 | minor | F.DIST, F.DIST.RT, F.INV and F.INV.RT accept degrees of freedom at the 10-billion boundary; F.INV uses the complementary tail, with a gamma-tail limit when numerator degrees dominate, to preserve inverse accuracy; values above the limit remain invalid | +| 2026-10-31 | minor | T.DIST returns `#DIV/0!` in density mode and `#NUM!` in cumulative mode when degrees truncate to zero; negative integer degrees remain `#NUM!` | | 2026-10-27 | minor | ECMA.CEILING added to the functions that are in our library but not on Microsoft's list (with USDOLLAR), so the counts don't change | | 2026-10-26 | minor | IMSQRT uses Excel's polar route with its cosine reduction, so `IMSQRT("-4")` is `1.22514845490862E-16+2i` as in Excel (exact `2i` before); the rows list the IM* differences still open | | 2026-10-25 | minor | LAMBDA row: a LAMBDA that calls itself more than 140 times, and a formula nested past the depth limit, give `#NUM!` (#1809; nesting gave `#CALC!` before). `=Foo(1)` where the defined name Foo holds `#N/A` gives `#N/A`, not `#NAME?` |