File tree 3 files changed +11
-5
lines changed
3 files changed +11
-5
lines changed Original file line number Diff line number Diff line change 290
290
([x y] (list 'js* " ((~{} < ~{}) ? ~{} : ~{})" x y x y))
291
291
([x y & more] `(min (min ~x ~y) ~@more)))
292
292
293
- (defmacro mod [num div]
293
+ (defmacro js- mod [num div]
294
294
(list 'js* " (~{} % ~{})" num div))
295
295
296
296
(defmacro bit-not [x]
Original file line number Diff line number Diff line change @@ -1311,15 +1311,20 @@ reduces them without incurring seq initialization"
1311
1311
[x]
1312
1312
(fix x))
1313
1313
1314
+ (defn js-mod
1315
+ " Modulus of num and div with original javascript behavior. i.e. bug for negative numbers"
1316
+ [n d]
1317
+ (cljs.core/js-mod n d))
1318
+
1314
1319
(defn mod
1315
1320
" Modulus of num and div. Truncates toward negative infinity."
1316
1321
[n d]
1317
- (cljs.core/ mod n d))
1322
+ (js- mod ( + ( js-mod n d) d) d))
1318
1323
1319
1324
(defn quot
1320
1325
" quot[ient] of dividing numerator by denominator."
1321
1326
[n d]
1322
- (let [rem (mod n d)]
1327
+ (let [rem (js- mod n d)]
1323
1328
(fix (/ (- n rem) d))))
1324
1329
1325
1330
(defn rem
@@ -1527,7 +1532,7 @@ reduces them without incurring seq initialization"
1527
1532
(loop [h 0 s (seq m)]
1528
1533
(if s
1529
1534
(let [e (first s)]
1530
- (recur (mod (+ h (bit-xor (hash (key e)) (hash (val e))))
1535
+ (recur (js- mod (+ h (bit-xor (hash (key e)) (hash (val e))))
1531
1536
4503599627370496 )
1532
1537
(next s)))
1533
1538
h)))
@@ -1537,7 +1542,7 @@ reduces them without incurring seq initialization"
1537
1542
(loop [h 0 s (seq s)]
1538
1543
(if s
1539
1544
(let [e (first s)]
1540
- (recur (mod (+ h (hash e)) 4503599627370496 )
1545
+ (recur (js- mod (+ h (hash e)) 4503599627370496 )
1541
1546
(next s)))
1542
1547
h)))
1543
1548
Original file line number Diff line number Diff line change 156
156
(assert (= (apply mod [4 2 ]) 0 ))
157
157
(assert (= (mod 3 2 ) 1 ))
158
158
(assert (= (apply mod [3 2 ]) 1 ))
159
+ (assert (= (mod -2 5 ) 3 ))
159
160
160
161
(assert (= [4 3 2 1 0 ] (loop [i 0 j ()]
161
162
(if (< i 5 )
You can’t perform that action at this time.
0 commit comments