Skip to content

Commit 1e5e5be

Browse files
timmcstuarthalloway
authored andcommitted
CLJ-827: Add bit-shift-right-logical
Signed-off-by: Gabriel Horner <gabriel.horner@gmail.com> Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
1 parent b50c03e commit 1e5e5be

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

src/clj/clojure/core.clj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,6 +1317,12 @@
13171317
:added "1.0"}
13181318
[x n] (. clojure.lang.Numbers shiftRight x n))
13191319

1320+
(defn bit-shift-right-logical
1321+
"Bitwise shift right, without sign-extension."
1322+
{:inline (fn [x n] `(. clojure.lang.Numbers (shiftRightLogical ~x ~n)))
1323+
:added "1.4"}
1324+
[x n] (. clojure.lang.Numbers shiftRightLogical x n))
1325+
13201326
(defn integer?
13211327
"Returns true if n is an integer"
13221328
{:added "1.0"

src/jvm/clojure/lang/Intrinsics.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ private static Object[] oa(Object... arr){
2929
"public static long clojure.lang.Numbers.remainder(long,long)", LREM,
3030
"public static long clojure.lang.Numbers.shiftLeft(long,long)", oa(L2I, LSHL),
3131
"public static long clojure.lang.Numbers.shiftRight(long,long)", oa(L2I, LSHR),
32+
"public static long clojure.lang.Numbers.shiftRightLogical(long,long)", oa(L2I, LUSHR),
3233
"public static double clojure.lang.Numbers.minus(double)", DNEG,
3334
"public static double clojure.lang.Numbers.minus(double,double)", DSUB,
3435
"public static double clojure.lang.Numbers.inc(double)", oa(DCONST_1, DADD),
3536
"public static double clojure.lang.Numbers.dec(double)", oa(DCONST_1, DSUB),
3637
"public static long clojure.lang.Numbers.quotient(long,long)", LDIV,
3738
"public static int clojure.lang.Numbers.shiftLeftInt(int,int)", ISHL,
3839
"public static int clojure.lang.Numbers.shiftRightInt(int,int)", ISHR,
40+
"public static int clojure.lang.Numbers.shiftRightLogicalInt(int,int)", IUSHR,
3941
"public static int clojure.lang.Numbers.unchecked_int_add(int,int)", IADD,
4042
"public static int clojure.lang.Numbers.unchecked_int_subtract(int,int)", ISUB,
4143
"public static int clojure.lang.Numbers.unchecked_int_negate(int)", INEG,

src/jvm/clojure/lang/Numbers.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,23 @@ static public long shiftRight(long x, long n){
389389
return x >> n;
390390
}
391391

392+
static public int shiftRightLogicalInt(int x, int n){
393+
return x >>> n;
394+
}
395+
396+
static public long shiftRightLogical(Object x, Object y){
397+
return shiftRightLogical(bitOpsCast(x),bitOpsCast(y));
398+
}
399+
static public long shiftRightLogical(Object x, long y){
400+
return shiftRightLogical(bitOpsCast(x),y);
401+
}
402+
static public long shiftRightLogical(long x, Object y){
403+
return shiftRightLogical(x,bitOpsCast(y));
404+
}
405+
static public long shiftRightLogical(long x, long n){
406+
return x >>> n;
407+
}
408+
392409
final static class LongOps implements Ops{
393410
public Ops combine(Ops y){
394411
return y.opsWith(this);

0 commit comments

Comments
 (0)