Repository navigation
prelude: parse String.toFloat natively with Ryu s2d + locale-safe strtod fallback - #1714
Merged
Merged
Conversation
mbouaziz
force-pushed
the
tofloat-native-s2d
branch
from
November 19, 2026 14:39
1578c20 to
ae47d93
Compare
…tod fallback Native used libc atof, which is locale-dependent (a ',' locale parses "1.5" as 1) and a different code path from Wasm. Use Ryu's s2d as the primary path on native too (correctly rounded, locale-independent, same as Wasm); inputs s2d rejects (more than 17 non-zero digits, an upstream Ryu limit) go to strtod after rewriting '.' to the locale's decimal point, so native and Wasm agree bit for bit for the decimal-only grammar validated in String.toFloatOption. Tests: native runtime test to_float_raw_native.c (runs on all platforms via run.sh, covers s2d path, >17-digit fallback, and a comma-decimal locale), edge formats and fallback rejections in the Wasm s2d harness (string_to_float.mjs), and grammar/rounding cases in tests/Float.sk. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai> Co-Authored-By: Claude Opus 5.5 (Anthropic, via Mistral Vibe; thinking: high) <noreply@anthropic.com>
Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai> Co-Authored-By: Claude Opus 5.5 (Anthropic, via Mistral Vibe; thinking: high) <noreply@anthropic.com>
mbouaziz
force-pushed
the
tofloat-native-s2d
branch
from
November 19, 2026 16:43
ae47d93 to
6544743
Compare
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.
What
Unifies
String.toFloatparsing across native and Wasm, and removes alocale hazard on native:
s2das the primary path (previously libcatof),exactly like Wasm — correctly rounded and locale-independent.
atof/strtodhonor the process locale (underde_DE.UTF-8,strtod("1.5")returns1.0). The fallback now rewritesthe input's
.tolocaleconv()->decimal_pointbefore callingstrtod,so parsing is correct under any installed locale. (The grammar is
validated in
String.toFloatOptionto be decimal-only, so.is the onlyseparator that can appear.)
s2dlimit) fall back tostrtodon native and JSNumber()on Wasm; both are correctly roundedfor decimal input, so native and Wasm agree bit for bit.
Tests
runtime/tests/to_float_raw_native.c, wired intorun.shbeforethe Linux-only section so it runs on macOS too: s2d-path values, the
>17-digit fallback,-0.0, overflow/underflow, and a realcomma-decimal locale (
de_DE.UTF-8when installed). Verified locally onmacOS: under
de_DE, plainstrtod("1.5")gives 1.0 while the runtimegives 1.5.
string_to_float.mjs(Wasm s2d harness): new accepted edge forms(
"5.","0.","1e0","10e-1","-0.0e0") checked against JSNumber(), plus more>17-digit rejection cases documenting the fallbacktrigger. Passed in the Linux container (100k random inputs included).
tests/Float.sk: grammar pins (toFloatOptionrejects whitespace, hex0x1p4,Infinity/INF, leading+,.5,1,5,00,1e+; accepts5.,0e0,1E5,10e-1), long-digit rounding(
"0.1000000000000000000000000000001"->0.1,"123456789012345678"->123456789012345680.0), the subnormal boundary(
"2.2250738585072011e-308"-> largest subnormal2.2250738585072009e-308),and a toString round-trip.
Validation
prelude/runtime/tests/run.shpasses on macOS (native toFloat test incl.the real
de_DE.UTF-8locale branch) and in the Linux container (fullsuite incl. Wasm s2d vs
Number()on 100k random inputs).string.ccompiles cleanly on both platforms (-Wall -Wextra -Werror).make check-fmtfailure on the first push was diagnosed and fixed inae47d93b:tests/Float.skneeded oneexpectEqon a single line.Re-verified locally with the pinned tool versions — skfmt (stage0 binary),
clang-format 20 on both
.cfiles, prettier 3.4.1 on the.mjs,shellcheck on
run.sh— all clean.build failure was GNU make 3.81 not supporting grouped
&:targets,causing two skargo runs to race on
state.db); prelude suite with thenew runtime is run against stage1 locally.
Notes
std0.7.0 bump, sothis PR no longer touches
Skargo.toml).compiled from source at every stage0 link). CI images republish (already
pending from Bump bootstrap to ab4bad9c and restore the FloatToString peephole fold #1688) will carry it.
trailers); validation performed in-session as described above.