Skip to content

Lexicographic ordering for <, <=, >, >= on text #105

Description

@garritfra

Follow-up to #68. That issue scoped equality (= / <>) for text and explicitly deferred ordering operators:

Ordering operators (<, <=, >, >=) on strings are a separate question and can be left as-is for now (numbers only) unless we want lexicographic ordering.

This is the separate question.

Current behavior

"a"<"b" returns #VALUE! — the ordering arm in crates/cell-sheet-core/src/formula/eval.rs still coerces both sides to f64 via cell_value_to_number, which errors on text.

Excel / Google Sheets behavior

Both treat the ordering operators as lexicographic on text:

  • "a"<"b"TRUE
  • "banana"<"apple"FALSE
  • "Foo"<"foo" → ? — this is where it gets interesting

Excel's text ordering is case-insensitive for < / > (matching its case-insensitive =). Google Sheets is the same. So "Foo"<"foo" is FALSE in both because they compare equal under case folding.

Open design questions

  1. Case sensitivity. Should ordering follow = and be case-insensitive? Strong yes for Excel parity. Implementation: lowercase both sides before comparing.
  2. Mixed-type ordering. What does 1<\"a\" mean? Excel sorts numbers before text before booleans, so 1<\"a\" is TRUE. We'll need a type-rank helper. Alternative: keep mixed-type ordering as #VALUE! and only support same-type ordering. Worth deciding explicitly.
  3. Bool ordering. Excel sorts booleans after text (\"z\"<TRUETRUE). Niche; consider whether to bother.
  4. Locale. Pure byte / Unicode-codepoint ordering, or locale-aware collation? Codepoint ordering is simplest and predictable; locale-aware needs ICU. Codepoint is probably fine for v1.

Acceptance criteria

  • \"a\"<\"b\" and similar return a Bool rather than #VALUE!.
  • Decision on case sensitivity documented in help/entries.rs (extend the = / <> entry, or add a new one).
  • Decision on mixed-type ordering documented.
  • Tests in cell-sheet-core cover same-type text ordering, case behavior, and the mixed-type decision.
  • Update the eval_ordering_on_text_still_errors regression test in eval.rs (currently locks in the deferred behavior).

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussionOpen-ended design discussionenhancementNew feature or requestformula-engineFormula tokenizer, parser, evaluator

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions