Repository navigation
fix(codegen): float_to_string on core WASM, one format everywhere (#643) - #810
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 55 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
|
Review these changes at https://app.gitnotebooks.com/hyperpolymath/affinescript/pull/810 |
float_to_string type-checked but failed core-WASM codegen with UnboundVariable, and the interpreter (string_of_float: "3.", 12 digits) disagreed with Bun (String(x): shortest round-trip). - lib/wasm_dtoa.ml: a shortest round-trip printer in raw WASM. It runs Burger & Dybvig's free-format digit generation on 40-limb bignums in linear memory, with no tables and no host import, and uses the ECMAScript Number::toString layout. Exact ties go to the even digit. It is emitted once per module, appended after every other function so no index moves; call sites are patched to it at assembly. Scratch space above the heap pointer is not kept, so a call holds only its result string. - lib/float_format.ml: the same format in OCaml. The interpreter's float_to_string uses it, so all three backends print the same text. - Tests: tests/codegen/test_float_to_string.mjs checks 22,655 doubles (powers of 2 and 10 and their neighbours, subnormals, extremes, ties, seeded random bit patterns) against Bun's String(x). test/test_float_format.ml pins the table, the interpreter and the module assembly. Closes #643 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0136P7Zo5h4xmXVEeSeQEDvw
267522186230338.625 is the double itself; the shorter literal relied on rounding, which SonarCloud flags (S6534). Also Number.NaN (S7773). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0136P7Zo5h4xmXVEeSeQEDvw
d7ac866 to
d491469
Compare
|
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |



Closes #643
What
float_to_stringtype-checked but failed core-WASM codegen withUnboundVariable. The interpreter's output (string_of_float:"3.", 12 digits) also disagreed with Bun'sString(x)(shortest round-trip). All three backends now print the same text, using the ECMAScriptNumber::toStringformat.lib/wasm_dtoa.ml: a shortest round-trip printer in raw WASM.lib/float_format.ml: the same format in OCaml. The interpreter'sfloat_to_stringuses it.float_to_stringare byte-for-byte unchanged.Behaviour change
The interpreter now prints
3.0as"3"(was"3.") and keeps up to 17 significant digits (was 12). This also changesstdlib/json.affine'sJFloatrendering in the interpreter, which now matches the Bun output.Tests
tests/codegen/test_float_to_string.mjschecks 22,655 doubles against Bun'sString(x). The cases are powers of 2 and 10 and their neighbouring doubles, subnormals, the extremes, exact ties, and seeded random bit patterns.test/test_float_format.mlpins the shared table, the interpreter, and the module assembly (printer appended, call patched, no placeholder left).dune test: 623 tests pass. All 39 WASM harnesses pass.just test-faces, the soundness ledger and the governance gates pass.Audit asked for in the issue
to_lowercase,to_uppercase,trim,string_subandstring_from_char_codeall compile on core WASM.showdoes not compile for any type (show(1)fails too). It needs type-directed lowering and is left out of this PR.Generated by Claude Code