js-on-sx: js-num-from-string uses string->number for exp-form
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 23s

Was computing m * pow(10, e) for "1.2345e-3" forms; floating-point
multiplication introduced rounding (Number(".12345e-3") -
0.00012345 == 2.7e-20). The SX string->number primitive parses the
whole literal in one IEEE round, matching JS literal parsing. Falls
back to manual m * pow(10, e) only when string->number returns nil.
built-ins/Number: 42/50 → 43/50. conformance.sh: 148/148.
This commit is contained in:
2026-05-07 20:47:29 +00:00
parent 2d475f95d1
commit 42cce5e3fc
4 changed files with 26 additions and 19 deletions

View File

@@ -1123,23 +1123,28 @@
(if
(>= esplit 0)
(let
((mant (js-string-slice trimmed 0 esplit))
(expstr
(js-string-slice
trimmed
(+ esplit 1)
(len trimmed))))
(let
((m (js-parse-decimal mant 0 0 1 false 0))
(e
(js-parse-decimal
expstr
0
0
1
false
0)))
(* m (pow 10 e))))
((parsed (string->number trimmed)))
(if
(= parsed nil)
(let
((mant (js-string-slice trimmed 0 esplit))
(expstr
(js-string-slice
trimmed
(+ esplit 1)
(len trimmed))))
(let
((m (js-parse-decimal mant 0 0 1 false 0))
(e
(js-parse-decimal
expstr
0
0
1
false
0)))
(* m (pow 10 e))))
parsed))
(js-parse-decimal
trimmed
0