Skip to content

Commit d56309e

Browse files
spinningtopsofdoomdnolen
authored and
dnolen
committed
CLJS-1594: NaN and both infinities cannot be elements of a set
Check if a number is Infinity, -Infinity, or NaN with isFinite then use matching hash values from Clojure for the values
1 parent 032077b commit d56309e

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/main/cljs/cljs/core.cljs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,14 @@
885885
(-hash ^not-native o)
886886

887887
(number? o)
888-
(js-mod (Math/floor o) 2147483647)
888+
(if (js/isFinite o)
889+
(js-mod (Math/floor o) 2147483647)
890+
(case o
891+
Infinity
892+
2146435072
893+
-Infinity
894+
-1048576
895+
2146959360))
889896

890897
(true? o) 1
891898

src/test/cljs/cljs/core_test.cljs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3125,6 +3125,12 @@
31253125
(-lookup [o k not-found] :3-arity))
31263126
[:foo]))))
31273127

3128+
(deftest test-cljs-1594
3129+
(is (not (js/isNaN (hash Infinity))))
3130+
(is (not (js/isNaN (hash -Infinity))))
3131+
(is (not (js/isNaN (hash NaN))))
3132+
(is (= (hash-set Infinity -Infinity 0 1 2 3 4 5 6 7 8)
3133+
(set (keys (zipmap [Infinity -Infinity 0 1 2 3 4 5 6 7 8] (repeat nil)))))))
31283134

31293135
(comment
31303136
;; ObjMap

0 commit comments

Comments
 (0)