Skip to content

fix(dart/core): preserve large numbers in formatString - #4196

Open
leoafarias wants to merge 1 commit into
a2ui-project:mainfrom
leoafarias:fix/format-string-large-numbers
Open

leoafarias wants to merge 1 commit into
a2ui-project:mainfrom
leoafarias:fix/format-string-large-numbers

Conversation

@leoafarias

Copy link
Copy Markdown

Description

Fixes #4193.

formatString printed whole numbers of 2^63 or more as 9223372036854775807 on the Dart VM and Wasm. _numberToString and _normalizeNumbers call toInt(), which clamps to the 64-bit limits, and _normalizeNumbers has no range check at all.

Solution

  1. Both functions call toInt() only for whole doubles in [-2^63, 2^63).
  2. Larger values keep their digits: a bare 1e20 prints 100000000000000000000. Inside a list or map the value stays a double, so jsonEncode writes [100000000000000000000.0], the right number with a .0.
  3. Updated the _normalizeNumbers doc comment and dart/a2ui_core/CHANGELOG.md.

Verification

  1. Added 36 cases to dart/a2ui_core/test/basic_catalog_test.dart: bare, list and object values around both 64-bit limits and 1e21, plus 1e300 and -1e300. 26 of them fail on main.
  2. dart test in dart/a2ui_core passes (2,398 tests), and so do dart analyze --fatal-infos and scripts/fix_format.sh --check.
  3. The same cases print identically on the VM and Wasm and correctly in a JS build, both run in Node.

Pre-launch Checklist

One time:

For this PR:

  • I have updated the relevant CHANGELOG.md file.
  • I updated/added relevant documentation.
  • My code changes (if any) have tests.
  • If my branch is on a fork, I have verified that scripts/e2e_test.sh passes.

I haven't run a sample or scripts/e2e_test.sh: both need an agent backed by a live model and an API key I don't have set up here.

If you need help, consider asking for advice on the discussion board.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request fixes an issue in formatString where whole doubles outside the signed 64-bit range were being clamped. It updates _numberToString and _normalizeNumbers in function_support.dart to ensure that only integral doubles within the signed 64-bit range are converted to integers, while larger values remain as doubles to prevent clamping. Additionally, comprehensive tests have been added to verify this behavior across various large number boundaries and structures. I have no further feedback to provide.

@github-actions github-actions Bot added the status: needs-triage auto-managed: https://github.com/a2ui-project/a2ui/blob/main/scripts/triage.mjs label Nov 12, 2026
@Varun-S10 Varun-S10 self-assigned this Nov 13, 2026
@github-actions github-actions Bot removed the status: needs-triage auto-managed: https://github.com/a2ui-project/a2ui/blob/main/scripts/triage.mjs label Nov 13, 2026
@Varun-S10

Copy link
Copy Markdown
Collaborator

Hi @leoafarias, thank you for raising this PR and we verified that it fixes large number formatting in formatString.
Hi @gspencergoog, could you please take a look?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: a2ui_core's formatString prints numbers of 2^63 or more as 9223372036854775807

2 participants