Skip to content

refactor: name number literals by parsing and printing their double - #1073

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

mbouaziz merged 2 commits into
mainfrom
simplify-numbers

Conversation

@mbouaziz

Copy link
Copy Markdown
Contributor

Now that Skip parses floats correctly rounded and prints them with Ryu (SkipLabs/skip#1287, #1288), normalizeJSNumber names each literal directly: it parses the literal to a double, then prints that double with jsNumberToString (the JS String() form).

This removes the exact decimal pipeline (normalizeDecimalJS, parseRadixInt, normalizeUnsignedJSNumber) and the second beyond-precision pass (canonicalizeBeyondPrecision). src/JSNumericString.sk goes from 276 changed lines to a net reduction of about 90 lines.

Commits (tests first):

  1. 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.
  2. refactor: makes the switch. A leading . gets a 0 prepended, 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 test locally. A differential run on 2,000 random literals (decimal, leading/trailing dot, exponent, hex, binary, separators) matches node's String(Number(x)) on every literal.

— Mistral Vibe

mbouaziz and others added 2 commits November 18, 2026 16:33
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
mbouaziz enabled auto-merge November 18, 2026 16:33
@mbouaziz
mbouaziz merged commit 1eecb30 into main Nov 18, 2026
1 check passed
@mbouaziz
mbouaziz deleted the simplify-numbers branch November 18, 2026 16:45
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
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