Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLJS-417 #44

Open
wants to merge 1 commit into
base: cljs_in_cljs
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/clj/cljs/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@
([x y] (list 'js* "((~{} < ~{}) ? ~{} : ~{})" x y x y))
([x y & more] `(min (min ~x ~y) ~@more)))

(defmacro mod [num div]
(defmacro js-mod [num div]
(list 'js* "(~{} % ~{})" num div))

(defmacro bit-not [x]
Expand Down
13 changes: 9 additions & 4 deletions src/cljs/cljs/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -1322,15 +1322,20 @@ reduces them without incurring seq initialization"
[x]
(fix x))

(defn js-mod
"Modulus of num and div with original javascript behavior. i.e. bug for negative numbers"
[n d]
(cljs.core/js-mod n d))

(defn mod
"Modulus of num and div. Truncates toward negative infinity."
[n d]
(cljs.core/mod n d))
(js-mod (+ (js-mod n d) d) d))

(defn quot
"quot[ient] of dividing numerator by denominator."
[n d]
(let [rem (mod n d)]
(let [rem (js-mod n d)]
(fix (/ (- n rem) d))))

(defn rem
Expand Down Expand Up @@ -1538,7 +1543,7 @@ reduces them without incurring seq initialization"
(loop [h 0 s (seq m)]
(if s
(let [e (first s)]
(recur (mod (+ h (bit-xor (hash (key e)) (hash (val e))))
(recur (js-mod (+ h (bit-xor (hash (key e)) (hash (val e))))
4503599627370496)
(next s)))
h)))
Expand All @@ -1548,7 +1553,7 @@ reduces them without incurring seq initialization"
(loop [h 0 s (seq s)]
(if s
(let [e (first s)]
(recur (mod (+ h (hash e)) 4503599627370496)
(recur (js-mod (+ h (hash e)) 4503599627370496)
(next s)))
h)))

Expand Down
1 change: 1 addition & 0 deletions test/cljs/cljs/core_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
(assert (= (apply mod [4 2]) 0))
(assert (= (mod 3 2) 1))
(assert (= (apply mod [3 2]) 1))
(assert (= (mod -2 5) 3))

(assert (= [4 3 2 1 0] (loop [i 0 j ()]
(if (< i 5)
Expand Down
2 changes: 1 addition & 1 deletion web/vendor/jq-console