2017-08-11 58 views
0

起初我以爲這是一個錯誤,但看看源代碼顯然是故意的。有人知道爲什麼這樣做嗎?它與Clojure不兼容,也是錯誤的微妙來源。ClojureScript漂浮散列作爲整數

(hash 1) ; => 1 
(hash 1.5) ; => 1 

https://github.com/clojure/clojurescript/blob/master/src/main/cljs/cljs/core.cljs#L985

(defn hash 
    "Returns the hash code of its argument. Note this is the hash code 
    consistent with =." 
    [o] 
    (cond 
    (implements? IHash o) 
    (bit-xor (-hash ^not-native o) 0) 

    (number? o) 
    (if (js/isFinite o) 
     (js-mod (Math/floor o) 2147483647) 
     (case o 
     Infinity 
     2146435072 
     -Infinity 
     -1048576 
     2146959360)) 
    ...)) 

回答