@@ -798,6 +798,22 @@ reduces them without incurring seq initialization"
798
798
([x y & more]
799
799
(reduce min (min x y) more)))
800
800
801
+ (defn- fix [q]
802
+ (if (>= q 0 )
803
+ (js* " (Math.floor(~{q}))" )
804
+ (js* " (Math.ceil(~{q}))" )))
805
+
806
+ (defn mod [n d]
807
+ (js* " (~{n} % ~{d})" ))
808
+
809
+ (defn quot [n d]
810
+ (let [rem (mod n d)]
811
+ (fix (js* " ((~{n} - ~{rem}) / ~{d})" ))))
812
+
813
+ (defn rem [n d]
814
+ (let [q (quot n d)]
815
+ (js* " (~{n} - (~{d} * ~{q}))" )))
816
+
801
817
(defn bit-xor
802
818
" Bitwise exclusive or"
803
819
[x y] (js* " (~{x} ^ ~{y})" ))
@@ -3119,6 +3135,43 @@ reduces them without incurring seq initialization"
3119
3135
(assert (= (find {:a 1 } nil ) nil ))
3120
3136
(assert (= (find {:a 1 :b 2 } nil ) nil ))
3121
3137
(assert (= (find [1 2 3 ] 0 ) [0 1 ]))
3138
+
3139
+ ; ; mod,quot,rem
3140
+ (assert (= (quot 4 2 ) 2 ))
3141
+ (assert (= (quot 3 2 ) 1 ))
3142
+ (assert (= (quot 6 4 ) 1 ))
3143
+ (assert (= (quot 0 5 ) 0 ))
3144
+ (assert (= (quot 42 5 ) 8 ))
3145
+ (assert (= (quot 42 -5 ) -8 ))
3146
+ (assert (= (quot -42 -5 ) 8 ))
3147
+ (assert (= (quot 9 3 ) 3 ))
3148
+ (assert (= (quot 9 -3 ) -3 ))
3149
+ (assert (= (quot -9 3 ) -3 ))
3150
+ (assert (= (quot 2 -5 ) 0 ))
3151
+ (assert (= (quot -2 5 ) 0 ))
3152
+ (assert (= (quot 0 3 ) 0 ))
3153
+ (assert (= (quot 0 -3 ) 0 ))
3154
+
3155
+ (assert (= (mod 4 2 ) 0 ))
3156
+ (assert (= (mod 3 2 ) 1 ))
3157
+ (assert (= (mod 6 4 ) 2 ))
3158
+ (assert (= (mod 0 5 ) 0 ))
3159
+ (assert (= (mod 4.5 2.0 ) 0.5 ))
3160
+ (assert (= (mod 42 5 ) 2 ))
3161
+ (assert (= (mod 9 3 ) 0 ))
3162
+ (assert (= (mod 9 -3 ) 0 ))
3163
+ (assert (= (mod -9 3 ) 0 ))
3164
+ (assert (= (mod -9 -3 ) 0 ))
3165
+ (assert (= (mod 0 3 ) 0 ))
3166
+ (assert (= (mod 3216478362187432 432143214 ) 120355456 ))
3167
+
3168
+ (assert (= (rem 4 2 ) 0 ))
3169
+ (assert (= (rem 0 5 ) 0 ))
3170
+ (assert (= (rem 4.5 2.0 ) 0.5 ))
3171
+ (assert (= (rem 42 5 ) 2 ))
3172
+ (assert (= (rem 2 5 ) 2 ))
3173
+ (assert (= (rem 2 -5 ) 2 ))
3174
+ (assert (= (rem 0 3 ) 0 ))
3122
3175
3123
3176
:ok
3124
3177
)
0 commit comments