Repository navigation
refactor: name number literals by parsing and printing their double - #1073
Merged
Merged
Conversation
A leading or trailing dot, zero padding past the float parser's input limit, and a literal still too long after the padding is dropped. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
Skip's String.toFloatOption is now correctly rounded and Float.toString prints the shortest round-trip digits (Ryu, SkipLabs/skip#1287/#1288), so normalizeJSNumber can name every literal by the String() form of its double directly: parse (radix digits converted to decimal first), print with jsNumberToString. This replaces the exact decimal pipeline (normalizeDecimalJS, parseRadixInt, normalizeUnsignedJSNumber) and the second beyond-precision pass (canonicalizeBeyondPrecision). Long zero-padded spellings that exceed the runtime parser's input limit are compacted first (compactDecimal), and a leading '.' gets a 0, so the pinned edge spellings keep their names. No behavior change: the full suite and a 2,000-literal differential run against node agree. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
mbouaziz
enabled auto-merge
November 18, 2026 16:33
mbouaziz
force-pushed
the
simplify-numbers
branch
from
November 18, 2026 16:33
7447fd3 to
91f517b
Compare
mbouaziz
added a commit
that referenced
this pull request
Nov 18, 2026
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
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.
Now that Skip parses floats correctly rounded and prints them with Ryu (SkipLabs/skip#1287, #1288),
normalizeJSNumbernames each literal directly: it parses the literal to a double, then prints that double withjsNumberToString(the JSString()form).This removes the exact decimal pipeline (
normalizeDecimalJS,parseRadixInt,normalizeUnsignedJSNumber) and the second beyond-precision pass (canonicalizeBeyondPrecision).src/JSNumericString.skgoes from 276 changed lines to a net reduction of about 90 lines.Commits (tests first):
test:pins the spellings the runtime parser does not accept as written:.5,5., zero padding past the 255-byte parser limit, and a literal that is still too long after the padding is dropped.refactor:makes the switch. A leading.gets a0prepended, and long zero-padded spellings are compacted first (compactDecimal), so those pins keep their names.There is no behavior change, so there is no version bump. Both commits pass
make testlocally. A differential run on 2,000 random literals (decimal, leading/trailing dot, exponent, hex, binary, separators) matches node'sString(Number(x))on every literal.— Mistral Vibe