diff --git a/lib/js/runtime.sx b/lib/js/runtime.sx index 5fa5abdc..7a2a56a1 100644 --- a/lib/js/runtime.sx +++ b/lib/js/runtime.sx @@ -1365,6 +1365,7 @@ ((= v true) 1) ((= v false) 0) ((= (type-of v) "number") v) + ((= (type-of v) "rational") (exact->inexact v)) ((= (type-of v) "string") (js-string-to-number v)) ((= (type-of v) "dict") (cond diff --git a/plans/js-on-sx.md b/plans/js-on-sx.md index 15b95568..bbcb2e59 100644 --- a/plans/js-on-sx.md +++ b/plans/js-on-sx.md @@ -158,6 +158,8 @@ Each item: implement → tests → update progress. Mark `[x]` when tests green. Append-only record of completed iterations. Loop writes one line per iteration: date, what was done, test count delta. +- 2026-05-09 — **`js-to-number` now coerces SX rationals via `exact->inexact`.** SX `(/ 59 16)` returns the rational `59/16` with `(type-of)` `"rational"` — not `"number"` — so `js-to-number` was falling through to the dict branch and ultimately returning `0`. That broke any path that did integer-divide intermediate math (e.g. `js-hex-2` for percent-encoding: `(js-math-trunc (/ 59 16))` was returning 0, so `encodeURIComponent(";")` produced `"%0B"` instead of `"%3B"`). Added a `((= (type-of v) "rational") (exact->inexact v))` clause in `js-to-number` between the existing `"number"` and `"string"` branches. Result: built-ins/encodeURIComponent 9/30 → 15/30, built-ins/encodeURI 22/60 → 28/60, built-ins/decodeURI 11/60 → 20/60. Object/Array unchanged. conformance.sh: 148/148. + - 2026-05-09 — **`parseFloat("+")` / `parseFloat("-")` / `parseFloat(".")` return NaN (were returning 0).** `js-float-prefix-end` happily consumed leading `+`/`-` and dot characters even with no digits — and `js-parse-num-safe` of those characters returned 0. Per spec, the prefix must contain at least one digit. Added a `js-str-has-digit?` walker called between `js-float-prefix-end` and `js-parse-num-safe`; if no digit is present in the consumed slice, return NaN. Result: built-ins/parseFloat 20/30 → 23/30, built-ins/parseInt 22/30 → 24/30. Number unchanged. conformance.sh: 148/148. - 2026-05-09 — **`parseFloat` recognises `"Infinity"` / `"±Infinity"` prefixes (not just exact matches).** Per spec, parseFloat parses the longest StrDecimalLiteral prefix — `Infinity` is one — so `parseFloat("Infinity1")`, `parseFloat("Infinityx")`, `parseFloat("Infinity+1")` should all return `Infinity`. Was only matching `s === "Infinity"` / `"+Infinity"` / `"-Infinity"` exactly. Added `js-float-has-infinity-prefix?` helper and three new branches at the top of `js-parse-float-prefix`. Result: built-ins/parseFloat 17/30 → 20/30. conformance.sh: 148/148.