Skip to content

M8a: $formatNumber + $formatBase half-even fix#26

Merged
flearc merged 3 commits into
mainfrom
feature/m8a-formatnumber
Jun 25, 2026
Merged

M8a: $formatNumber + $formatBase half-even fix#26
flearc merged 3 commits into
mainfrom
feature/m8a-formatnumber

Conversation

@flearc

@flearc flearc commented Jun 25, 2026

Copy link
Copy Markdown
Owner

Summary

  • $formatNumber(value, picture, options?) — a faithful Lua port of jsonata-js v2.2.1's XPath/XSLT 3.0 decimal-format picture formatter (F&O §4.7): splitParts → validate → analyse → 14-bullet format. Covers optional/mandatory digits (#/0/9), regular + explicit grouping, percent/per-mille (incl. custom symbols), exponent notation, the options decimal-format overrides, the Unicode digit family, and the D3080–D3093 picture-validation errors. New module src/jsonata/functions/formatnumber.lua (signature <n-so?:s>).
  • $formatBase fix — now rounds half-even (via the shared H.round_half_even) instead of flooring value/radix; $formatBase(99.5, 2.5)"1100100".
  • Faithful half-even roundingH.round_half_even ported from jsonata's round(): shifts the decimal via string (not multiply) then applies exact ties-to-even, eliminating a %.12g snap that dropped the 13th significant digit (affected $round/$formatBase/$formatNumber).

Suite impact

  • function-formatNumber 18 → 45/45; function-formatBase 8 → 9/9.
  • Official suite 1296 → 1324 / 1682 (≈78.7%), zero regressions (guard green).

Test Plan

  • 542/542 busted unit specs green; new spec/formatnumber_spec.lua covers the oracle-verified output matrix + 13-digit rounding fidelity + D3080 message.
  • Official-suite regression guard (spec/jsonata_suite_spec.lua) green.
  • Adversarial review vs jsonata-js v2.2.1 oracle (159 probes) — 2 bugs found and fixed; all now match the oracle.

🤖 Generated with Claude Code

flearc and others added 3 commits June 25, 2026 18:24
…t floor

$formatBase(99.5,2.5) must round 99.5->100; we floored to 99. Extract the
half-even rounding from $round into H.round_half_even and use it for value+radix
(and reuse it in $formatNumber next).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…nata port)

Ports jsonata formatNumber (F&O 4.7: splitParts/validate/analyse/format) into
functions/formatnumber.lua: optional/mandatory digits, regular+explicit
grouping, percent/per-mille, exponent, the options decimal-format overrides, and
the unicode digit family. D3080-D3093 picture-validation errors.

Adds the full function-formatNumber conformance group (case000-036 + issue785
zero-guard) to the suite baseline.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…sages

Adversarial review found two issues. (1) H.round_half_even's %.12g snap dropped
the 13th significant digit (e.g. $formatNumber(1234567890123,"0")); replace with
a faithful port of jsonata round() — shift the decimal via string, not multiply,
then exact ties-to-even. Fixes $round/$formatBase/$formatNumber for 13+ digit
values. (2) D3080-D3093 message strings now match jsonata verbatim (D3080 was a
copy-paste of the percent message; others said "picture string" not "sub-picture").

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@flearc flearc merged commit 7f91307 into main Jun 25, 2026
1 check passed
@flearc flearc deleted the feature/m8a-formatnumber branch June 25, 2026 14:11
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