M8a: $formatNumber + $formatBase half-even fix#26
Merged
Conversation
…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>
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
$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 modulesrc/jsonata/functions/formatnumber.lua(signature<n-so?:s>).$formatBasefix — now rounds half-even (via the sharedH.round_half_even) instead of flooringvalue/radix;$formatBase(99.5, 2.5)→"1100100".H.round_half_evenported from jsonata'sround(): shifts the decimal via string (not multiply) then applies exact ties-to-even, eliminating a%.12gsnap that dropped the 13th significant digit (affected$round/$formatBase/$formatNumber).Suite impact
function-formatNumber18 → 45/45;function-formatBase8 → 9/9.Test Plan
spec/formatnumber_spec.luacovers the oracle-verified output matrix + 13-digit rounding fidelity + D3080 message.spec/jsonata_suite_spec.lua) green.🤖 Generated with Claude Code