Skip to content
Permalink
Browse files

CLJS-936: Multi arity bitwise operators

Add support for multi-arity bitwise operators
  • Loading branch information...
jjttjj authored and swannodette committed Dec 30, 2014
1 parent 35d483c commit d1127ad101b9cf8c3d056132bb89bc970c323dc0
Showing with 31 additions and 10 deletions.
  1. +12 −4 src/cljs/cljs/core.cljs
  2. +19 −6 test/cljs/cljs/core_test.cljs
@@ -2031,19 +2031,27 @@ reduces them without incurring seq initialization"

(defn bit-xor
"Bitwise exclusive or"
[x y] (cljs.core/bit-xor x y))
([x y] (cljs.core/bit-xor x y))
([x y & more]
(reduce bit-xor (cljs.core/bit-xor x y) more)))

(defn bit-and
"Bitwise and"
[x y] (cljs.core/bit-and x y))
([x y] (cljs.core/bit-and x y))
([x y & more]
(reduce bit-and (cljs.core/bit-and x y) more)))

(defn bit-or
"Bitwise or"
[x y] (cljs.core/bit-or x y))
([x y] (cljs.core/bit-or x y))
([x y & more]
(reduce bit-or (cljs.core/bit-or x y) more)))

(defn bit-and-not
"Bitwise and"
[x y] (cljs.core/bit-and-not x y))
([x y] (cljs.core/bit-and-not x y))
([x y & more]
(reduce bit-and-not (cljs.core/bit-and-not x y) more)))

(defn bit-clear
"Clear bit at index n"
@@ -357,24 +357,37 @@

(deftest test-bit-operations
(testing "Testing bit operations"
(is (= [0 0 1 0 1]
(is (= [1 0 0 40 43 49 49])
[(bit-xor 0 1)
(bit-xor 1 1)
(bit-xor 1 0)
(bit-xor 41 1)
(bit-xor 42 1)
(bit-xor 42 1 26)
(apply bit-xor [42 1 26])])
(is (= [0 0 1 0 1 1 1]
[(bit-and 1 0)
(bit-and 0 0)
(bit-and 1 1)
(bit-and 42 1)
(bit-and 41 1)]))
(is (= [1 0 1 43 41]
(bit-and 41 1)
(bit-and 41 1 27)
(apply bit-and [41 1 27])]))
(is (= [1 0 1 43 41 59 59]
[(bit-or 1 0)
(bit-or 0 0)
(bit-or 1 1)
(bit-or 42 1)
(bit-or 41 1)]))
(is (= [1 0 0 42 40]
(bit-or 41 1)
(bit-or 41 1 26)
(apply bit-or [41 1 26])]))
(is (= [1 0 0 42 32 32]
[(bit-and-not 1 0)
(bit-and-not 0 0)
(bit-and-not 1 1)
(bit-and-not 42 1)
(bit-and-not 41 1)]))
(bit-and-not 41 1 27)
(apply bit-and-not [41 1 27])]))
(is (= [0 2 968 16649 0]
[(bit-clear 1 0)
(bit-clear 2 0)

0 comments on commit d1127ad

Please sign in to comment.
You can’t perform that action at this time.