From cd57d5480f445e3c2ada7740e4af3caea6c59dde Mon Sep 17 00:00:00 2001 From: Joe Gallo Date: Fri, 11 Nov 2011 13:10:42 -0500 Subject: [PATCH] add unsigned-bit-shift-right --- src/clj/clojure/core.clj | 6 ++++++ src/jvm/clojure/lang/Numbers.java | 21 +++++++++++++-------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj index 3d27076..24b03b0 100644 --- a/src/clj/clojure/core.clj +++ b/src/clj/clojure/core.clj @@ -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" diff --git a/src/jvm/clojure/lang/Numbers.java b/src/jvm/clojure/lang/Numbers.java index ee6bac0..62fb868 100644 --- a/src/jvm/clojure/lang/Numbers.java +++ b/src/jvm/clojure/lang/Numbers.java @@ -355,10 +355,6 @@ static public Number divide(BigInteger n, BigInteger d){ (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); -- 1.7.6.3