From 9fccec28af850e03aa49dc31b9ba1e040ee7f09a Mon Sep 17 00:00:00 2001 From: Harrison Booth <73434116+Harrison-Booth@users.noreply.github.com> Date: Fri, 30 Oct 2026 19:24:22 -0500 Subject: [PATCH 1/3] Handle zero-valued oversized bit shifts --- crates/functions/src/engineering.rs | 11 +++++++++++ docs/function-parity.md | 4 +++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/crates/functions/src/engineering.rs b/crates/functions/src/engineering.rs index dbe6734d3..a02196f41 100644 --- a/crates/functions/src/engineering.rs +++ b/crates/functions/src/engineering.rs @@ -175,6 +175,9 @@ fn bitxor(a: &[Arg], _c: &mut dyn Ctx) -> R { fn shift(a: &[Arg], left: bool) -> R { let n = bit_operand(a, 0)?; let s = num(a, 1)?.trunc(); + if n == 0 { + return Ok(Value::Number(0.0)); + } if s.abs() > 53.0 { return Err(CellError::Num); } @@ -446,6 +449,14 @@ mod tests { is_err(ev("BITAND", vec![n(1.5), n(5.0)]), CellError::Num); is_err(ev("BITLSHIFT", vec![n(1.0), n(54.0)]), CellError::Num); is_err(ev("BITLSHIFT", vec![n(2f64.powi(47)), n(1.0)]), CellError::Num); + for f in ["BITLSHIFT", "BITRSHIFT"] { + for shift in [-100.0, -54.0, 54.0, 100.0] { + close(ev(f, vec![n(0.0), n(shift)]), 0.0); + } + is_err(ev(f, vec![n(1.0), n(54.0)]), CellError::Num); + } + is_err(ev("BITLSHIFT", vec![n(0.0), t("bad")]), CellError::Value); + is_err(ev("BITRSHIFT", vec![n(-1.0), n(100.0)]), CellError::Num); } #[test] diff --git a/docs/function-parity.md b/docs/function-parity.md index d9823e8bf..02d8fe609 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-27 · **Change:** minor (ECMA.CEILING listed with USDOLLAR as not on Microsoft's list; earlier: IMSQRT reproduces the stray real part Excel gives for negative reals, and the other IM* differences from Excel are listed; 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 (BITLSHIFT and BITRSHIFT return zero for zero operands with shifts beyond 53 bits, as observed in Excel; earlier: ECMA.CEILING listed with USDOLLAR as not on Microsoft's list; IMSQRT reproduces Excel's stray real part for negative reals) · **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). @@ -29,6 +29,8 @@ Excel's worksheet functions, category by category, against GridCraft's function ## Coverage +| 2026-10-31 | minor | BITLSHIFT and BITRSHIFT return `0` for zero operands shifted beyond 53 bits in either direction; nonzero operands retain the `#NUM!` limit, matching Excel | + **Measured: 513 / 523 by name (98.1%); 504 / 523 working (96.4%).** | Category | Excel | Ours | Working | % working | Missing | From 5d89b9efdfbd2e425eead5cc97db36b32f3c41d6 Mon Sep 17 00:00:00 2001 From: Harrison Booth <73434116+Harrison-Booth@users.noreply.github.com> Date: Fri, 30 Oct 2026 19:34:19 -0500 Subject: [PATCH 2/3] Move bit shift parity note to revision history --- docs/function-parity.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/function-parity.md b/docs/function-parity.md index 02d8fe609..e3e9cb4de 100644 --- a/docs/function-parity.md +++ b/docs/function-parity.md @@ -29,8 +29,6 @@ Excel's worksheet functions, category by category, against GridCraft's function ## Coverage -| 2026-10-31 | minor | BITLSHIFT and BITRSHIFT return `0` for zero operands shifted beyond 53 bits in either direction; nonzero operands retain the `#NUM!` limit, matching Excel | - **Measured: 513 / 523 by name (98.1%); 504 / 523 working (96.4%).** | Category | Excel | Ours | Working | % working | Missing | @@ -126,6 +124,7 @@ workbooks; results checked in as data, not Excel files) and fixing what it finds | Date | Change | Summary | |---|---|---| +| 2026-10-31 | minor | BITLSHIFT and BITRSHIFT return `0` for zero operands shifted beyond 53 bits in either direction; nonzero operands retain the `#NUM!` limit, matching Excel | | 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?` | From 213b76af10172e832dc097d86f132869e41f1610 Mon Sep 17 00:00:00 2001 From: Harrison Booth <73434116+Harrison-Booth@users.noreply.github.com> Date: Fri, 30 Oct 2026 19:39:26 -0500 Subject: [PATCH 3/3] Expand bit shift boundary regressions --- crates/functions/src/engineering.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/crates/functions/src/engineering.rs b/crates/functions/src/engineering.rs index a02196f41..96d73bf78 100644 --- a/crates/functions/src/engineering.rs +++ b/crates/functions/src/engineering.rs @@ -450,12 +450,19 @@ mod tests { is_err(ev("BITLSHIFT", vec![n(1.0), n(54.0)]), CellError::Num); is_err(ev("BITLSHIFT", vec![n(2f64.powi(47)), n(1.0)]), CellError::Num); for f in ["BITLSHIFT", "BITRSHIFT"] { - for shift in [-100.0, -54.0, 54.0, 100.0] { + for shift in [-100.0, -54.0, -53.0, 53.0, 54.0, 100.0] { close(ev(f, vec![n(0.0), n(shift)]), 0.0); } - is_err(ev(f, vec![n(1.0), n(54.0)]), CellError::Num); + for shift in [-100.0, -54.0, 54.0, 100.0] { + is_err(ev(f, vec![n(1.0), n(shift)]), CellError::Num); + } + if f == "BITLSHIFT" { + is_err(ev(f, vec![n(1.0), n(53.0)]), CellError::Num); + } else { + close(ev(f, vec![n(1.0), n(53.0)]), 0.0); + } + is_err(ev(f, vec![n(0.0), t("bad")]), CellError::Value); } - is_err(ev("BITLSHIFT", vec![n(0.0), t("bad")]), CellError::Value); is_err(ev("BITRSHIFT", vec![n(-1.0), n(100.0)]), CellError::Num); }