js-on-sx: rational handling in typeof/to-string/strict-eq/loose-eq
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 24s

This commit is contained in:
2026-05-09 04:53:11 +00:00
parent 9bf4bd6180
commit 41dbac55b8
2 changed files with 21 additions and 4 deletions

View File

@@ -1304,6 +1304,7 @@
((= v nil) "object")
((= (type-of v) "boolean") "boolean")
((= (type-of v) "number") "number")
((= (type-of v) "rational") "number")
((= (type-of v) "string") "string")
((= (type-of v) "lambda") "function")
((= (type-of v) "function") "function")
@@ -1322,6 +1323,7 @@
((= (type-of v) "list") "[object Array]")
((= (type-of v) "string") "[object String]")
((= (type-of v) "number") "[object Number]")
((= (type-of v) "rational") "[object Number]")
((= (type-of v) "boolean") "[object Boolean]")
((or (= (type-of v) "lambda") (= (type-of v) "function") (= (type-of v) "component"))
"[object Function]")
@@ -1731,6 +1733,7 @@
((= v false) "false")
((= (type-of v) "string") v)
((= (type-of v) "number") (js-number-to-string v))
((= (type-of v) "rational") (js-number-to-string (exact->inexact v)))
(else
(if
(= (type-of v) "dict")
@@ -2055,6 +2058,14 @@
js-bitnot
(fn (a) (- 0 (+ (js-num-to-int (js-to-number a)) 1))))
(define
js-numeric-type?
(fn (v) (or (= (type-of v) "number") (= (type-of v) "rational"))))
(define
js-numeric-norm
(fn (v) (if (= (type-of v) "rational") (exact->inexact v) v)))
(define
js-strict-eq
(fn
@@ -2062,6 +2073,10 @@
(cond
((and (js-undefined? a) (js-undefined? b)) true)
((or (js-undefined? a) (js-undefined? b)) false)
((and (js-numeric-type? a) (js-numeric-type? b))
(let
((an (js-numeric-norm a)) (bn (js-numeric-norm b)))
(if (or (js-number-is-nan an) (js-number-is-nan bn)) false (= an bn))))
((not (= (type-of a) (type-of b))) false)
(else
(if (or (js-number-is-nan a) (js-number-is-nan b)) false (= a b))))))
@@ -2076,10 +2091,10 @@
((js-strict-eq a b) true)
((and (= a nil) (js-undefined? b)) true)
((and (js-undefined? a) (= b nil)) true)
((and (= (type-of a) "number") (= (type-of b) "string"))
(= a (js-to-number b)))
((and (= (type-of a) "string") (= (type-of b) "number"))
(= (js-to-number a) b))
((and (js-numeric-type? a) (= (type-of b) "string"))
(= (js-numeric-norm a) (js-to-number b)))
((and (= (type-of a) "string") (js-numeric-type? b))
(= (js-to-number a) (js-numeric-norm b)))
((= (type-of a) "boolean") (js-loose-eq (js-to-number a) b))
((= (type-of b) "boolean") (js-loose-eq a (js-to-number b)))
((and (dict? a) (contains? (keys a) "__js_string_value__"))