Skip to content

fix(js): avoid precision loss in negative varint64 fast path - #3992

Merged
chaokunyang merged 2 commits into
apache:mainfrom
ayush00git:fix/zigzag-mapping-bigint
Aug 29, 2026
Merged

fix(js): avoid precision loss in negative varint64 fast path#3992
chaokunyang merged 2 commits into
apache:mainfrom
ayush00git:fix/zigzag-mapping-bigint

Conversation

@ayush00git

@ayush00git ayush00git commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Why?

zigzag is computed in double precision, so any negative value with magnitude above 2^52 rounds to an even zigzag and decodes as positive: -4503599627370497n round-trips as +4503599627370496n. Also reachable through writeSliInt64.

What does this PR do?

the writeVarInt64 fast path now requires v >= -(2^52) in both the number and safe-range bigint branches; anything more negative falls through to the exact bigint zigzag (v << 1n) ^ (v >> 63n). writeSliInt64 is fixed too since its big-long path delegates here. A short comment on the new constant records the invariant.

Related issues

AI Contribution Checklist

  • Substantial AI assistance was used in this PR: yes / no
  • If yes, I included a completed AI Contribution Checklist in this PR description and the required AI Usage Disclosure.
  • If yes, my PR description includes the required ai_review summary and screenshot evidence or equivalent persisted links of the final clean AI review results from both fresh reviewers described in AI_POLICY.md, the Fory-guided reviewer and the independent general reviewer, on the current PR diff or current HEAD after the latest code changes.

Does this PR introduce any user-facing change?

  • Does this PR introduce any public API change?
  • Does this PR introduce any binary protocol compatibility change?

Benchmark

@chaokunyang
chaokunyang merged commit 792ab50 into apache:main Aug 29, 2026
64 checks passed
@ayush00git
ayush00git deleted the fix/zigzag-mapping-bigint branch August 29, 2026 17:05
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