Skip to content

refactor: simplify number handling via stdlib Ryu + Math.fmod, EFNum carries a Float - #1077

Merged
mbouaziz merged 1 commit into
mainfrom
numbers-ryu-fmod
Nov 19, 2026
Merged

mbouaziz merged 1 commit into
mainfrom
numbers-ryu-fmod

Conversation

@mbouaziz

Copy link
Copy Markdown
Contributor

Simplifies the number-literal machinery now that the Skip stdlib provides Ryu-based Float.toString (shortest round-trip, SkipLabs/skip#1288) and Math.fmod (SkipLabs/skip#1711):

  • jsNumberToString / shortestFloatDigits are now total: Ryu's shortest digits always read back to the same double, so the round-trip guard is gone
  • Enum constant folding carries doubles end-to-end: EFNum(Float) instead of EFNum(String); the literal name is produced by jsNumberToString only when a member value is materialized
  • JS % over doubles folds with Math.fmod (exactly the truncated remainder with the dividend's sign, NaN cases included), replacing a hand-rolled Sterbenz loop; enumDoubleInt32Base uses it too

No behavior change: full test suite passes (230 tests), and the checker binary produces identical results to the previous one on positive/negative enum-folding and literal-naming repros. New pins: jsNumberToString unit test and enum remainder cases (5.5 % 2 = 1.5, -5.5 % 2 = -1.5, 1e309 % 2 = NaN -> number), verified against tsc --strict. Version bumped to 1.26.3 per the every-PR rule.

Generated by Mistral Vibe (co-authored with the commit via Co-Authored-By: Mistral Vibe <vibe@mistral.ai>).

…carries a Float

- jsNumberToString and shortestFloatDigits are now total: since std 0.5.0
  (SkipLabs/skip#1288) Float.toString is Ryu's shortest round-trip form,
  whose digits always read back to the same double, so the round-trip guard
  in jsNumberToString is gone
- enum constant folding keeps doubles end-to-end: EFNum(Float) instead of
  EFNum(String); the literal name is produced by jsNumberToString only when
  the member value is materialized, and string concatenation renders it
  there
- JS % over doubles folds with the stdlib Math.fmod (C fmod is exactly the
  truncated remainder with the dividend's sign, NaN cases included), replacing
  the hand-rolled Sterbenz loop; enumDoubleInt32Base uses it too

No behavior change: full test suite passes (230 tests), and the checker
binary produces identical results to the previous one on positive and
negative enum-folding and literal-naming repros. New pins: jsNumberToString
unit test, enum remainder cases (5.5 % 2 = 1.5, -5.5 % 2 = -1.5,
1e309 % 2 = NaN -> number) matching tsc.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
@mbouaziz
mbouaziz merged commit a3f06ff into main Nov 19, 2026
1 check passed
@mbouaziz
mbouaziz deleted the numbers-ryu-fmod branch November 19, 2026 22:16
mbouaziz added a commit that referenced this pull request Nov 19, 2026
…x parsing (#1078)

Follow-up to #1077 (merged), continuing the Numbers simplification now
that the stdlib has Ryu-based `Float.toString` and `Math.fmod`:

- `isJSNumericString` is now a round-trip check (parse, print back,
compare) instead of a hand-rolled grammar — with Ryu + the
correctly-rounded runtime parser, "s is canonical iff it parses to a
finite double that prints as s", exactly tsc's `(+s).toString() === s`
numeric-name test. The iterator-based decimal/exponent scanners,
`isDigitChar`, `isPreciseJSNumberLiteral`, the `normalizeJSNumber` fast
path and the `isJSNumberLiteralStringForm` alias all go away (-113 lines
net)
- `jsNumberLiteralDouble` is now total: `radixToDecimalString` returns
None on invalid digits instead of throwing in `Chars.hexDigitToInt` —
fixes a checker crash on `keyof { "0x1p3": ... }`-style property names
(pinned in `keyof.ts`)
- `enumDoubleInt32Base` is just `Math.fmod(f, 2^32)` for every finite
double; shift counts share `enumShiftCount`

Behavior note: the round-trip check also rejects spellings the old
grammar accepted but that are not real canonical forms, matching JS/tsc
exactly — `"9e+308"` (String is `"Infinity"`) and `"9e-324"` (String is
`"1e-323"`); pins updated. Full suite green (230 tests).

Generated by Mistral Vibe (co-authored with the commit via
`Co-Authored-By: Mistral Vibe <vibe@mistral.ai>`).
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