Skip to content

Add opt-in BigDecimal support for precise numeric evaluation - #2

Merged
copyleftdev merged 2 commits into
mainfrom
feat/issue-1-bigdecimal
Oct 23, 2026
Merged

copyleftdev merged 2 commits into
mainfrom
feat/issue-1-bigdecimal

Conversation

@copyleftdev

Copy link
Copy Markdown
Owner

JSON numbers currently pass through f64, losing precision, and numeric functions reject the decimal strings in #1. This adds an optional bigdecimal feature that enables serde_json/arbitrary_precision and preserves decimal values through numeric evaluation. Default behavior remains unchanged.

The paid-order example now returns "300.55": 100.30 + 200.25 = 300.55 (the issue's expected "300.95" is an arithmetic typo).

  • Add decimal arithmetic, numeric functions, comparisons, sorting, hashing, and serialization, including precise JSON input and expression literals.
  • Accept decimal strings in numeric functions; string operands produce string results, while number-only inputs produce JSON numbers. $number explicitly converts strings to numbers.
  • Add regression coverage for precision boundaries, rounding, mixed inputs, bindings, serialization, and invalid arguments.
  • Add CI checks for both feature configurations and update both READMEs and installation documentation with a runnable example and a Git dependency for the unreleased feature.

Local validation passed: workspace tests with the feature disabled and enabled, Clippy with warnings denied in both configurations, formatting, documentation builds, and the README example's regression test.

The existing JSONata compatibility runner reports failures without failing its test command. Default mode reports 1,027 passing cases, 4 existing failures, and 549 skipped cases. Decimal mode reports 1,018 passing cases, 13 failures, and 549 skipped cases: the same 4 existing failures plus 9 expected differences from accepting numeric strings, supporting numbers outside the f64 range, and preserving string-conversion precision.

Documented limits: inexact operations follow BigDecimal's precision rules (normally 100 significant digits); $power supports integer and half-integer exponents and returns D3061 for other fractional exponents; $round uses half-even rounding with precision from -10,000 to 10,000. $random retains its existing behavior. Inputs already rounded through Rust floating-point literals cannot regain lost precision.

Refs #1.

Preserve arbitrary-precision JSON numbers and expression literals with the
bigdecimal feature. Use decimal arithmetic in numeric functions and
operators, with precise comparisons, sorting, hashing, and serialization.
Accept decimal strings in numeric functions and return string results when
string operands are supplied, while keeping the default behavior unchanged.

Add regression coverage for issue #1, precision boundaries, rounding,
mixed inputs, bindings, and invalid arguments. Correct the example's
expected total to 300.55. Document precision and power/rounding limits and
run both feature configurations in CI.

Validation: workspace tests, Clippy with warnings denied, formatting, and
documentation builds pass. The compatibility report retains four existing
failures; decimal mode adds nine expected semantic differences.

Refs #1
@coderabbitai

coderabbitai Bot commented Oct 23, 2026

Copy link
Copy Markdown

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b368e6f7-cf21-49a9-ae41-6de11e1864e7
📥 Commits

Reviewing files that changed from the base of the PR and between 46a0afc and 8bb32f5.

📒 Files selected for processing: 23
  • .github/workflows/ci.yml
  • CHANGELOG.md
  • README.md
  • crates/seuil/Cargo.toml
  • crates/seuil/README.md
  • crates/seuil/src/decimal.rs
  • crates/seuil/src/evaluator/engine.rs
  • crates/seuil/src/evaluator/functions/array.rs
  • crates/seuil/src/evaluator/functions/mod.rs
  • crates/seuil/src/evaluator/functions/numeric_decimal.rs
  • crates/seuil/src/evaluator/functions/object.rs
  • crates/seuil/src/evaluator/functions/type_ops.rs
  • crates/seuil/src/evaluator/value/impls.rs
  • crates/seuil/src/evaluator/value/mod.rs
  • crates/seuil/src/evaluator/value/serialize.rs
  • crates/seuil/src/lib.rs
  • crates/seuil/src/parser/ast.rs
  • crates/seuil/src/parser/pratt.rs
  • crates/seuil/src/parser/process.rs
  • crates/seuil/src/parser/tokenizer.rs
  • crates/seuil/tests/bigdecimal.rs
  • crates/seuil/tests/issue_1.rs
  • docs/src/installation.md
+---------------------------------------------------------+
| Eliminate bugs. Ship early. Sleep well. Pick all three. |
+---------------------------------------------------------+
  \
   \     /)/)
        ( '')
        /  |
      o(___)
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@copyleftdev
copyleftdev merged commit a203120 into main Oct 23, 2026
5 of 6 checks passed
@copyleftdev
copyleftdev deleted the feat/issue-1-bigdecimal branch October 23, 2026 04:43
@copyleftdev copyleftdev mentioned this pull request Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant