Skip to content

Keep long, ulong and uint bits in JavaScript bitwise and shift operators - #322

Merged
matt-edmondson merged 1 commit into
mainfrom
claude/project-thread-kddtpg-256
Oct 22, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
claude/project-thread-kddtpg-256

Conversation

@matt-edmondson

@matt-edmondson matt-edmondson commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Before: JavaScript converts the operands of &, |, ^, <<, >> and ~ to signed 32-bit integers. As a result, flags | 4294967296L gave 1, and a uint above 2^31 came out negative.

After: bitwise and shift operators on long, ulong and uint operands keep all their bits in the generated JavaScript.

How: a 64-bit operation is now done in BigInt and wrapped with BigInt.asIntN/asUintN. A uint result is read back with >>> 0, and a uint right shift uses >>>. Compound assignments, shifts included, are written out the same way. WideIntegerBitwiseOperatorTests covers them.

Fixes #256

https://claude.ai/code/session_018tZnrna9oooMZHDaLyXumk


Generated by Claude Code

…ors [patch]

JavaScript converts the operands of &, |, ^, <<, >> and ~ to a signed
32-bit integer, so flags | 4294967296L gave 1 and a uint above 2^31 came
out negative. A 64-bit operation is now done in BigInt and wrapped with
asIntN/asUintN; a uint one is read back with >>> 0 and right-shifted with
>>>. Compound assignments, shifts included, are written out the same way.

Fixes #256

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018tZnrna9oooMZHDaLyXumk
@sonarqubecloud

Copy link
Copy Markdown

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.

JavaScript: bitwise and shift operators on long/uint values give 32-bit-truncated results (flags | 4294967296L → 1)

2 participants