Repository navigation
feat: fold enum arithmetic over doubles, as tsc does - #1075
Merged
Merged
Conversation
mbouaziz
enabled auto-merge
November 19, 2026 00:09
Fractional, past-2^53 and overflowing arithmetic, bitwise operators on fractional operands and division by zero widen the member to number; tsc folds each to the literal of its double. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
Enum member initializers now fold with JS double semantics instead of exact integers within 2^53: operands are parsed with jsNumberLiteralDouble, the operator is applied on Float, and the result is named by jsNumberToString. So 0.1 + 0.2 is 0.30000000000000004, 1.5 * 2 is 3, 2 ** 53 + 1 is 9007199254740992, 1e308 * 10 is Infinity, and fractional auto-increment (1.5, then 2.5) folds too. % is computed exactly (truncated remainder by repeated exact subtraction); bitwise operators and ~ apply ToInt32/ToUint32 to any double. A NaN result, division by zero (a -0 divisor is named 0, so its sign is lost) and powers other than exact integers within 2^53 (engines round those last bits differently) stay an untracked number. A 3,000-initializer differential run against node agrees on every folded value (version 1.26.0). Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
mbouaziz
force-pushed
the
enum-fold-doubles
branch
from
November 19, 2026 00:09
ce86e1c to
540fe2e
Compare
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.
Stacked on #1074. Merge that one first; this PR's base will then switch to main.
Enum member initializers used to fold only exact integers within 2^53, so everything else widened to
number. They now fold with JS double semantics: parse each operand withjsNumberLiteralDouble, apply the operator onFloat, and name the result withjsNumberToString. This matches tsc:0.1 + 0.2number0.300000000000000041.5 * 2number310 / 3number3.33333333333333352 ** 53 + 1number90071992547409921e308 * 10numberInfinity1.5 | 0,-2.7 >> 0,~1.5,1e300 | 0number1,-2,-2,01.5number2.5(removes a FIXME)How each operator is handled:
%is computed exactly: a truncated remainder by repeated exact subtraction, since Skip has no fmod.~apply ToInt32/ToUint32 to any double.number, which is sound but stricter than tsc:-0divisor is named0and the sign of the infinite result is lost;Commits (tests first):
test:pins the currentnumberresults.feat:does the folding, flips the pins, and updatesskjs-rules.md(enums). Version 1.26.0.make testpasses on both commits locally. A differential run of 3,000 random initializers (all 12 operators over fractional, huge, tiny, int32-edge and past-2^53 operands) matches node on every folded value. The 260 that staynumberare all powers, NaN remainders, or divisions by zero.— Mistral Vibe