Permalink
Browse files

add unsigned-bit-shift-right

  • Loading branch information...
1 parent ba930d9 commit c30cf125b3db6459a8e07a9bab68b83f784c546a @joegallo committed Nov 11, 2011
Showing with 19 additions and 8 deletions.
  1. +6 −0 src/clj/clojure/core.clj
  2. +13 −8 src/jvm/clojure/lang/Numbers.java
View
@@ -1300,6 +1300,12 @@
:added "1.0"}
[x n] (. clojure.lang.Numbers shiftRight x n))
+(defn unsigned-bit-shift-right
+ "Unsigned bitwise shift right"
+ {:inline (fn [x n] `(. clojure.lang.Numbers (unsignedShiftRight ~x ~n)))
+ :added "1.4"}
+ [x n] (. clojure.lang.Numbers unsignedShiftRight x n))
+
(defn integer?
"Returns true if n is an integer"
{:added "1.0"
@@ -355,10 +355,6 @@ else if(d.equals(BigInteger.ONE.negate()))
(d.signum() < 0 ? d.negate() : d));
}
-static public int shiftLeftInt(int x, int n){
- return x << n;
-}
-
static public long shiftLeft(Object x, Object y){
return shiftLeft(bitOpsCast(x),bitOpsCast(y));
}
@@ -372,10 +368,6 @@ static public long shiftLeft(long x, long n){
return x << n;
}
-static public int shiftRightInt(int x, int n){
- return x >> n;
-}
-
static public long shiftRight(Object x, Object y){
return shiftRight(bitOpsCast(x),bitOpsCast(y));
}
@@ -389,6 +381,19 @@ static public long shiftRight(long x, long n){
return x >> n;
}
+static public long unsignedShiftRight(Object x, Object y){
+ return unsignedShiftRight(bitOpsCast(x),bitOpsCast(y));
+}
+static public long unsignedShiftRight(Object x, long y){
+ return unsignedShiftRight(bitOpsCast(x),y);
+}
+static public long unsignedShiftRight(long x, Object y){
+ return unsignedShiftRight(x,bitOpsCast(y));
+}
+static public long unsignedShiftRight(long x, long n){
+ return x >>> n;
+}
+
final static class LongOps implements Ops{
public Ops combine(Ops y){
return y.opsWith(this);

0 comments on commit c30cf12

Please sign in to comment.