Repository navigation
An integer literal past 64 bits is a number; an uncaught number reads as JS writes it - #785
Merged
Merged
Conversation
… 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two follow-ups found while fixing #780 (PR #783).
1. An integer literal past 64 bits is a
numberAn integer literal that does not fit in 64 bits was cut to its low 64 bits:
123456789012345680000evaluated to-5670419503621181000, with no diagnostic. Past 128 bits it was an error. It is now anumber, the nearest double, as in JS:123456789012345680000-567041950362118100012345678901234568000018446744073709551616(2^64)184467440737095520001e+42InfinityLiterals 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)
describeUncaughtinjit.cppformatted a thrown number with%.17g:throw 1e-7saiduncaught exception: 9.9999999999999995e-08. It now uses the same algorithm as__ts_number_to_string(shortest round-trip digits, JS layout) and saysuncaught exception: 1e-7.Tests
00integer_literal_past_64_bits.ts(test-compile-andtest-jit-). Its values were checked against node, apart from the deliberate integer case below 2^63.uncaught/throw_number_shortest.tsunder gc, rc and none, expectinguncaught exception: 1e-7.ctest -C Release -j 16): 6696/6696 passed. No existing expectation changed.🤖 Generated with Claude Code