Skip to content

fix(laya-ts): spell floats >= 1e16 like CPython in serializeState - #1341

Merged
NandhaKishorM merged 1 commit into
NandhaKishorM:mainfrom
thread3d:fix/laya-ts-serialize-exponent
Oct 24, 2026
Merged

NandhaKishorM merged 1 commit into
NandhaKishorM:mainfrom
thread3d:fix/laya-ts-serialize-exponent

Conversation

@thread3d

Copy link
Copy Markdown
Contributor

What

pyNumber switches to exponent notation at 1e16 and above as well as below 1e-4, with CPython's sign and two-digit exponent.

Why

The port reproduced CPython's lower switch but not its upper one, so a state carrying 1e16 -- an amount, an id, a timestamp -- was serialized as 10000000000000000 here and 1e+16 in Python. That text is the model input: measured with the real tokenizer, the same state is 8 state tokens in Python and 6 here, so the model answered a different prompt with no warning.

How it was verified

cd laya-ts && npx vitest run tests/parity-sequence.test.ts

Checklist

  • Focused on one change (split unrelated work into another PR)
  • Rebased on the latest main (branch cut from upstream/main at 0.4.14)
  • Tests pass locally
  • Docs or examples updated when the public API changed

pyNumber reproduced CPython's lower switch to exponent notation (below 1e-4) but not its
upper one (1e16 and above), so a state carrying 1e16 -- an amount, an id, a timestamp --
was serialized as 10000000000000000 here and 1e+16 in Python. That text is the model
input: measured with the real tokenizer, the same state is 8 state tokens in Python and 6
here, so the model answered a different prompt with no warning. JavaScript's own Number
toString switches at 1e21, which is why the upper bound had to be written rather than
inherited.

The parity test asserted the divergent spelling as expected ("an integer-valued number
reads as a Python int"), which is true below 1e16 only; it now pins both bounds, the sign,
and the padded exponent (1e+16, 1.5e+16, -1e+16, 1e+308) alongside the existing small ones.
@NandhaKishorM
NandhaKishorM merged commit e87f2d2 into NandhaKishorM:main Oct 24, 2026
46 of 50 checks passed
NandhaKishorM added a commit that referenced this pull request Oct 24, 2026
33 PRs. Server hardening (#1331, #1332, #1333), TypeScript parity
(#1330, #1336, #1337, #1338, #1339, #1340, #1341, #1342, #1343),
fail-closed input handling in evals and the integrations (#1317, #1318,
#1319, #1320, #1321, #1322, #1326, #1335), exact and faster script
detection (#1334, #1349), JVM and .NET resource handling (#1327, #1328,
#1329, #1346), port goldens and clipping (#1324 excluded, #1325, #1344,
#1345), CI (#1323, #1347, #1348).

Verified before tagging: all 92 suites pass, 610 tests. ruff clean on
both lists. laya-ts 1247 tests across 44 files, tsc --noEmit clean.
Version agrees across pyproject.toml, laya.__version__ and nix/package.nix.
README carries 0.4.15 only.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@thread3d
thread3d deleted the fix/laya-ts-serialize-exponent branch October 28, 2026 10:37
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.

2 participants