Repository navigation
refactor: simplify number handling via stdlib Ryu + Math.fmod, EFNum carries a Float - #1077
Merged
Merged
Conversation
…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
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>`).
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.
Simplifies the number-literal machinery now that the Skip stdlib provides Ryu-based
Float.toString(shortest round-trip, SkipLabs/skip#1288) andMath.fmod(SkipLabs/skip#1711):jsNumberToString/shortestFloatDigitsare now total: Ryu's shortest digits always read back to the same double, so the round-trip guard is goneEFNum(Float)instead ofEFNum(String); the literal name is produced byjsNumberToStringonly when a member value is materialized%over doubles folds withMath.fmod(exactly the truncated remainder with the dividend's sign, NaN cases included), replacing a hand-rolled Sterbenz loop;enumDoubleInt32Baseuses it tooNo 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:
jsNumberToStringunit test and enum remainder cases (5.5 % 2 = 1.5,-5.5 % 2 = -1.5,1e309 % 2 = NaN -> number), verified againsttsc --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>).