js-on-sx: Math.hypot and Math.cbrt honour NaN/Infinity/+-0 edges
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 24s

This commit is contained in:
2026-05-10 12:32:14 +00:00
parent 1e29bba1be
commit 019a0c6105
2 changed files with 37 additions and 13 deletions

View File

@@ -3987,25 +3987,47 @@
(x)
(let
((n (js-to-number x)))
(if
(< n 0)
(- 0 (pow (- 0 n) (/ 1 3)))
(pow n (/ 1 3))))))
(cond
((js-number-is-nan n) (js-nan-value))
((= n (js-infinity-value)) (js-infinity-value))
((= n (- 0 (js-infinity-value))) n)
((= n 0) n)
((< n 0) (- 0 (pow (- 0 n) (/ 1.0 3.0))))
(else (pow n (/ 1.0 3.0)))))))
(define
js-math-hypot
(fn (&rest args) (sqrt (js-math-hypot-loop args 0))))
(fn
(&rest args)
(let
((status (js-math-hypot-scan args false false 0)))
(cond
((= (first status) "inf") (js-infinity-value))
((= (first status) "nan") (js-nan-value))
(else (sqrt (nth status 1)))))))
(define
js-math-hypot-loop
js-math-hypot-scan
(fn
(args acc)
(if
(empty? args)
acc
(let
((n (js-to-number (first args))))
(js-math-hypot-loop (rest args) (+ acc (* n n)))))))
(args saw-inf? saw-nan? acc)
(cond
((empty? args)
(cond
(saw-inf? (list "inf"))
(saw-nan? (list "nan"))
(else (list "ok" acc))))
(else
(let
((n (js-to-number (first args))))
(cond
((= n (js-infinity-value))
(js-math-hypot-scan (rest args) true saw-nan? acc))
((= n (- 0 (js-infinity-value)))
(js-math-hypot-scan (rest args) true saw-nan? acc))
((js-number-is-nan n)
(js-math-hypot-scan (rest args) saw-inf? true acc))
(else
(js-math-hypot-scan (rest args) saw-inf? saw-nan? (+ acc (* n n))))))))))
(begin
(define js-math-sin (fn (x) (sin (js-to-number x))))