fix(formula-engine): typed equality for = and <> (closes #68)#107
Merged
Conversation
Closes #68. Previously `=` and `<>` unconditionally coerced both operands to numbers, so `IF(A1=C3, A2, 0)` returned `#VALUE!` when either cell held text. Switch the equality arm to a typed compare so values are matched within their own type (number/text/bool/empty), with mixed types returning FALSE for `=` and TRUE for `<>` to match Excel and Google Sheets. Text equality is case-insensitive via Unicode-aware `to_lowercase` — also matches Excel/Sheets `=` semantics. Ordering operators (`<`, `<=`, `>`, `>=`) remain numeric-only; the issue defers lexicographic ordering as a separate question, and a test locks in the current behaviour so any future change is explicit. Adds 11 eval-layer unit tests covering text/text, bool/bool, mixed types, the issue's `IF(A1=C3, A2, 0)` example with text cells, and case-insensitivity. Documents the new semantics in `FORMULA_ENTRIES` (a new `=`/`<>` help entry) and in the CHANGELOG under `Unreleased`. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
=and<>now do typed comparison instead of coercing both operands tof64. Closes Equality operator (=) should work on strings #68.FALSEfor=/TRUEfor<>rather than#VALUE!.<,<=,>,>=) remain numeric-only — that's the deferred scope from Equality operator (=) should work on strings #68 and is now tracked separately in Lexicographic ordering for<,<=,>,>=on text #105.eval_ordering_on_text_still_errors) locks in the current ordering-on-text behaviour so any future relaxation is an explicit decision.=/<>entry inFORMULA_ENTRIESdocumenting the type-by-type rules and the case-insensitivity choice.Excel / Sheets parity
Verified by hand against Excel and Google Sheets. Matches:
"foo"="foo"/"foo"="FOO"(case-insensitive) → TRUE1="1"/TRUE="TRUE"/TRUE=1(mixed types) → FALSE1<>"1"→ TRUETwo follow-ups filed for the divergences I found while verifying:
<,<=,>,>=on text #105 — lexicographic ordering for<,<=,>,>=on text""should be equal (matches Excel/Sheets) #106 — empty cell=""should be TRUE (currently FALSE because empty cell-refs coerce to0)Neither is in scope for this PR.
Test plan
cargo test --workspace— 36/36 eval tests pass, 32/32 integration tests passcargo clippy --workspace --all-targets -- -D warningscleancargo fmt --all --checkcleanIF(A1=C3, A2, 0)example with text cells, and case-insensitivity=/<>and ordering tests still pass (no regression)🤖 Generated with Claude Code