From 550085f8b849632c426cd265ffbf2a842c77d658 Mon Sep 17 00:00:00 2001 From: Harrison Booth <73434116+Harrison-Booth@users.noreply.github.com> Date: Fri, 30 Oct 2026 19:33:10 -0500 Subject: [PATCH 1/4] G710: return division error for zero T degrees --- crates/functions/src/stat/distributions.rs | 8 +++++++- crates/functions/src/stat/tests.rs | 11 +++++++++++ docs/function-parity.md | 3 ++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/crates/functions/src/stat/distributions.rs b/crates/functions/src/stat/distributions.rs index cb2f0398a..40e7d5223 100644 --- a/crates/functions/src/stat/distributions.rs +++ b/crates/functions/src/stat/distributions.rs @@ -173,7 +173,13 @@ 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(); + if v == 0.0 { + return Err(CellError::Div0); + } + if v < 1.0 { + return Err(CellError::Num); + } 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 87ce19fac..75ae50f9b 100644 --- a/crates/functions/src/stat/tests.rs +++ b/crates/functions/src/stat/tests.rs @@ -404,6 +404,17 @@ fn t_chi_f() { is_err(ev("F.DIST", vec![n(1.0), n(0.0), n(4.0), b(true)]), CellError::Num); } +#[test] +fn t_dist_degrees_truncating_to_zero_return_div0() { + 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(-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 bf57fcd3e..316c9cd97 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-15 · **Last updated:** 2026-10-25 · **Change:** minor (the LAMBDA row lists the recursion limit and its `#NUM!`, and the error a defined name holding an error gives when called; earlier: number text with accounting parentheses coerces like Excel 365; INDEX with one index on a 2-D reference is #REF! as in Excel; earlier: 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!` when truncated degrees of freedom are zero; earlier: the LAMBDA row lists the recursion limit and its `#NUM!`, and the error a defined name holding an error gives when called; earlier: number text with accounting parentheses coerces like Excel 365; INDEX with one index on a 2-D reference is #REF! as in Excel; earlier: 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). @@ -123,6 +123,7 @@ workbooks; results checked in as data, not Excel files) and fixing what it finds | Date | Change | Summary | |---|---|---| +| 2026-10-31 | minor | T.DIST returns `#DIV/0!` when degrees truncate to zero; negative integer degrees remain `#NUM!` | | 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?` | | 2026-10-23 | minor | Number text coercion (VALUE, arithmetic, typed entry): a dollar sign before accounting parentheses (`$(1,234)`, `$ (5)`) and a percent sign after them (`(5)%`) read as negatives; `(-5)`, `((5))`, `($-5)`, `$5%`, `$(5)%` and dates or times in parentheses are `#VALUE!`, as observed in Excel 365 | | 2026-10-23 | minor | INDEX with only a row index on a reference of several rows and columns (`INDEX(A1:C3,2)`, `INDEX(A1:C3,0)`) is `#REF!`, as observed in Excel, so it also fails as a range endpoint and inside other functions; an empty column argument (`INDEX(A1:C3,2,)`) still gives the row. Checked that a column array with one index stays a 1×1 array (`TYPE` 64), which is what Excel returns | From ad69d4cbdd5ce524000a1409edec74a1a2cecb06 Mon Sep 17 00:00:00 2001 From: Harrison Booth <73434116+Harrison-Booth@users.noreply.github.com> Date: Fri, 30 Oct 2026 19:39:00 -0500 Subject: [PATCH 2/4] G710: update zero-degree test error --- crates/functions/src/stat/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/functions/src/stat/tests.rs b/crates/functions/src/stat/tests.rs index 75ae50f9b..a5bb21f9b 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); From 3b61d660e911242ac8af73d2bcea7cee9fb39669 Mon Sep 17 00:00:00 2001 From: Harrison Booth <73434116+Harrison-Booth@users.noreply.github.com> Date: Fri, 30 Oct 2026 20:51:47 -0500 Subject: [PATCH 3/4] Return NUM for invalid T distribution degrees --- crates/functions/src/stat/distributions.rs | 8 +------- crates/functions/src/stat/tests.rs | 8 ++++---- 2 files changed, 5 insertions(+), 11 deletions(-) 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); From a0da53f576154efbab7c13260e28e9e1106d896c Mon Sep 17 00:00:00 2001 From: Harrison Booth <73434116+Harrison-Booth@users.noreply.github.com> Date: Fri, 30 Oct 2026 20:53:00 -0500 Subject: [PATCH 4/4] Match T DIST zero degree errors by mode --- crates/functions/src/stat/distributions.rs | 8 +++++++- crates/functions/src/stat/tests.rs | 4 ++-- docs/function-parity.md | 4 ++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/crates/functions/src/stat/distributions.rs b/crates/functions/src/stat/distributions.rs index cb2f0398a..f42d06b05 100644 --- a/crates/functions/src/stat/distributions.rs +++ b/crates/functions/src/stat/distributions.rs @@ -173,8 +173,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 86d9393dd..c4d608a03 100644 --- a/crates/functions/src/stat/tests.rs +++ b/crates/functions/src/stat/tests.rs @@ -405,9 +405,9 @@ fn t_chi_f() { } #[test] -fn t_dist_degrees_truncating_below_one_return_num() { +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::Num); + 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); diff --git a/docs/function-parity.md b/docs/function-parity.md index 316c9cd97..d66e691b0 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 (T.DIST gives `#DIV/0!` when truncated degrees of freedom are zero; earlier: the LAMBDA row lists the recursion limit and its `#NUM!`, and the error a defined name holding an error gives when called; earlier: number text with accounting parentheses coerces like Excel 365; INDEX with one index on a 2-D reference is #REF! as in Excel; earlier: 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: the LAMBDA row lists the recursion limit and its `#NUM!`, and the error a defined name holding an error gives when called; earlier: number text with accounting parentheses coerces like Excel 365; INDEX with one index on a 2-D reference is #REF! as in Excel; earlier: 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). @@ -123,7 +123,7 @@ workbooks; results checked in as data, not Excel files) and fixing what it finds | Date | Change | Summary | |---|---|---| -| 2026-10-31 | minor | T.DIST returns `#DIV/0!` when degrees truncate to zero; negative integer degrees remain `#NUM!` | +| 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-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?` | | 2026-10-23 | minor | Number text coercion (VALUE, arithmetic, typed entry): a dollar sign before accounting parentheses (`$(1,234)`, `$ (5)`) and a percent sign after them (`(5)%`) read as negatives; `(-5)`, `((5))`, `($-5)`, `$5%`, `$(5)%` and dates or times in parentheses are `#VALUE!`, as observed in Excel 365 | | 2026-10-23 | minor | INDEX with only a row index on a reference of several rows and columns (`INDEX(A1:C3,2)`, `INDEX(A1:C3,0)`) is `#REF!`, as observed in Excel, so it also fails as a range endpoint and inside other functions; an empty column argument (`INDEX(A1:C3,2,)`) still gives the row. Checked that a column array with one index stays a 1×1 array (`TYPE` 64), which is what Excel returns |