Repository navigation
feat: compare number literal names by name - #1074
Merged
Merged
Conversation
mbouaziz
force-pushed
the
simplify-numbers
branch
from
November 18, 2026 16:33
7447fd3 to
91f517b
Compare
…terals Distinct names of distinct doubles with more than 15 significant digits or at the double range's edges get no always-false warning today; tsc reports TS2367 on each. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
Every number literal name is now the String() form of its double, except spellings too long for the runtime parser, which normalizeJSNumber keeps. String() is a function of the double, so two distinct exact names denote distinct doubles. The name helpers reduce to one predicate, isExactJSNumberName: jsNumberLiteralsMayCollide, the truthiness helpers, isJSNumberLiteralStringForm and the comparison lint's imprecision check all compare exact names by name, and treat a kept spelling as any value. The always-false comparison warning now fires on distinct literals with more than 15 significant digits or at the double range's edges, as tsc reports TS2367 on them (version 1.25.0). Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
mbouaziz
force-pushed
the
simplify-number-names
branch
from
November 18, 2026 17:01
4f3077c to
dabf421
Compare
mbouaziz
added a commit
that referenced
this pull request
Nov 19, 2026
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 with `jsNumberLiteralDouble`, apply the operator on `Float`, and name the result with `jsNumberToString`. This matches tsc: | Initializer | Before | Now (= tsc) | | --- | --- | --- | | `0.1 + 0.2` | `number` | `0.30000000000000004` | | `1.5 * 2` | `number` | `3` | | `10 / 3` | `number` | `3.3333333333333335` | | `2 ** 53 + 1` | `number` | `9007199254740992` | | `1e308 * 10` | `number` | `Infinity` | | `1.5 \| 0`, `-2.7 >> 0`, `~1.5`, `1e300 \| 0` | `number` | `1`, `-2`, `-2`, `0` | | auto-increment after `1.5` | `number` | `2.5` (removes a FIXME) | How each operator is handled: - `%` is computed exactly: a truncated remainder by repeated exact subtraction, since Skip has no fmod. - Bitwise operators and `~` apply ToInt32/ToUint32 to any double. - Three cases stay `number`, which is sound but stricter than tsc: - a NaN result, since NaN has no literal type; - division by zero, because a `-0` divisor is named `0` and the sign of the infinite result is lost; - powers other than exact integers within 2^53, because engines differ in the last bit of non-integer powers. Commits (tests first): 1. `test:` pins the current `number` results. 2. `feat:` does the folding, flips the pins, and updates `skjs-rules.md` (enums). Version 1.26.0. `make test` passes 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 stay `number` are all powers, NaN remainders, or divisions by zero. — Mistral Vibe
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.
After #1073, every number literal name is the
String()form of its double. The only exception is a spelling too long for the runtime parser, which the normalizer keeps as written.String()is a function of the double, so two distinct exact names always denote distinct doubles.The name helpers now share one predicate,
isExactJSNumberName:jsNumberLiteralsMayCollide(equality narrowing /interMayEqual): distinct exact names never collide.jsNumberLiteralMayBeFalsy/jsNumberLiteralMayBeTruthy: an exact name is falsy only if it is0orNaN.isJSNumberLiteralStringForm(template holes, keyof, enum reverse maps): an exact name other thanNaN.hasImpreciseNumberLiteral: only kept spellings silence it.In all four, a kept spelling still means "any value", which is sound.
Behavior change (minor bump, 1.25.0): the always-false comparison warning now fires on distinct literals that have more than 15 significant digits or sit at the edges of the double range. For example,
0xffffffffffffffff === -1,9007199254740993 === 9007199254740994and1e308 === 1e-308. tsc reports TS2367 on each of these (checked locally).Commits (tests first):
test:pins the current silence on these comparisons.feat:simplifies the helpers, flips the pins to expected warnings, and adds unit tests for the kept-spelling cases.skjs-rules.mdrule 30 is updated.make testis green on both commits locally.— Mistral Vibe