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] 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 |