Skip to content

An integer literal past 64 bits is a number; an uncaught number reads as JS writes it - #785

Merged
ASDAlexander77 merged 1 commit into
mainfrom
fix-bigliteral-uncaught-number
Nov 8, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
fix-bigliteral-uncaught-number

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Two follow-ups found while fixing #780 (PR #783).

1. An integer literal past 64 bits is a number

An integer literal that does not fit in 64 bits was cut to its low 64 bits: 123456789012345680000 evaluated to -5670419503621181000, with no diagnostic. Past 128 bits it was an error. It is now a number, the nearest double, as in JS:

literal before after
123456789012345680000 -5670419503621181000 123456789012345680000
18446744073709551616 (2^64) wrapped 18446744073709552000
43 digits wrapped 1e+42
314 digits error: more than 128 bits Infinity

Literals in [2^63, 2^64) stay u64, as before. Their value is now exact: the signed string parse made them 65 bits wide, so they went to a 128-bit type and only the low word was read back. let max: u64 = 18446744073709551615 (00int64_remainder) keeps working. Literals below 2^63 are unchanged and stay integers (tslang's own rule).

The "integer literal is too large to represent (more than 128 bits)" error can no longer happen and is removed.

2. An uncaught thrown number reads as JS writes it (Windows JIT)

describeUncaught in jit.cpp formatted a thrown number with %.17g: throw 1e-7 said uncaught exception: 9.9999999999999995e-08. It now uses the same algorithm as __ts_number_to_string (shortest round-trip digits, JS layout) and says uncaught exception: 1e-7.

Tests

  • New: 00integer_literal_past_64_bits.ts (test-compile- and test-jit-). Its values were checked against node, apart from the deliberate integer case below 2^63.
  • New: uncaught/throw_number_shortest.ts under gc, rc and none, expecting uncaught exception: 1e-7.
  • Full Windows ctest (ctest -C Release -j 16): 6696/6696 passed. No existing expectation changed.

🤖 Generated with Claude Code

… as JS writes it

An integer literal that no 64-bit integer holds was cut to its low 64 bits
(123456789012345680000 read -5670419503621181000), and one past 128 bits
was an error. It is now a `number`, the nearest double, as in JS:
123456789012345680000, 2^64 -> 18446744073709552000, 1e313's digits ->
Infinity. A literal in [2^63, 2^64) stays a u64, now exactly: the signed
string parse made it 65 bits wide, which took a 128-bit type and read back
only its low word.

Under the Windows JIT, an uncaught thrown number was described with `%.17g`
(`9.9999999999999995e-08`). It now uses the shortest round-trip digits in JS
layout, as `"" + x` does since #783 (`uncaught exception: 1e-7`).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit a688eee into main Nov 8, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the fix-bigliteral-uncaught-number branch November 8, 2026 16:18
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.

1 participant