Skip to content

feat: compare number literal names by name - #1074

Merged
mbouaziz merged 2 commits into
mainfrom
simplify-number-names
Nov 18, 2026
Merged

mbouaziz merged 2 commits into
mainfrom
simplify-number-names

Conversation

@mbouaziz

@mbouaziz mbouaziz commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

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 is 0 or NaN.
  • isJSNumberLiteralStringForm (template holes, keyof, enum reverse maps): an exact name other than NaN.
  • The comparison lint's 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 === 9007199254740994 and 1e308 === 1e-308. tsc reports TS2367 on each of these (checked locally).

Commits (tests first):

  1. test: pins the current silence on these comparisons.
  2. feat: simplifies the helpers, flips the pins to expected warnings, and adds unit tests for the kept-spelling cases. skjs-rules.md rule 30 is updated.

make test is green on both commits locally.

— Mistral Vibe

Base automatically changed from simplify-numbers to main November 18, 2026 16:45
mbouaziz and others added 2 commits November 18, 2026 16:49
…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
mbouaziz force-pushed the simplify-number-names branch from 4f3077c to dabf421 Compare November 18, 2026 17:01
@mbouaziz
mbouaziz merged commit bc66944 into main Nov 18, 2026
1 check passed
@mbouaziz
mbouaziz deleted the simplify-number-names branch November 18, 2026 22:14
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
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