Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 6 additions & 15 deletions user/super/com/google/gwt/emul/java/lang/Integer.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,24 +184,15 @@ public static int reverseBytes(int i) {
}

public static int rotateLeft(int i, int distance) {
while (distance-- > 0) {
i = i << 1 | ((i < 0) ? 1 : 0);
}
return i;
int lowerBits = i >>> (SIZE - distance);
int upperBits = i << distance;
return upperBits | lowerBits;
}

public static int rotateRight(int i, int distance) {
int ui = i & MAX_VALUE; // avoid sign extension
int carry = (i < 0) ? 0x40000000 : 0; // MIN_VALUE rightshifted 1
while (distance-- > 0) {
int nextcarry = ui & 1;
ui = carry | (ui >> 1);
carry = (nextcarry == 0) ? 0 : 0x40000000;
}
if (carry != 0) {
ui = ui | MIN_VALUE;
}
return ui;
int upperBits = i << (SIZE - distance);
int lowerBits = i >>> distance;
return upperBits | lowerBits;
}

public static int signum(int i) {
Expand Down
21 changes: 6 additions & 15 deletions user/super/com/google/gwt/emul/java/lang/Long.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,24 +128,15 @@ public static long reverseBytes(long l) {
}

public static long rotateLeft(long i, int distance) {
while (distance-- > 0) {
i = i << 1 | ((i < 0) ? 1 : 0);
}
return i;
long lowerBits = i >>> (SIZE - distance);
long upperBits = i << distance;
return upperBits | lowerBits;
}

public static long rotateRight(long i, int distance) {
long ui = i & MAX_VALUE; // avoid sign extension
long carry = (i < 0) ? 0x4000000000000000L : 0; // MIN_VALUE rightshifted 1
while (distance-- > 0) {
long nextcarry = ui & 1;
ui = carry | (ui >> 1);
carry = (nextcarry == 0) ? 0 : 0x4000000000000000L;
}
if (carry != 0) {
ui = ui | MIN_VALUE;
}
return ui;
long upperBits = i << (SIZE - distance);
long lowerBits = i >>> distance;
return upperBits | lowerBits;
}

public static int signum(long i) {
Expand Down
6 changes: 6 additions & 0 deletions user/test/com/google/gwt/emultest/java/lang/IntegerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,19 @@ public void testRotateLeft() {
assertEquals(-1, Integer.rotateLeft(-1, 4));
assertEquals(Integer.MIN_VALUE, Integer.rotateLeft(0x40000000, 1));
assertEquals(1, Integer.rotateLeft(Integer.MIN_VALUE, 1));
assertEquals(Integer.MIN_VALUE, Integer.rotateLeft(Integer.MIN_VALUE, 0));
assertEquals(Integer.MIN_VALUE, Integer.rotateLeft(1, -1));
assertEquals(-1, Integer.rotateLeft(-1, 1000));
}

public void testRotateRight() {
assertEquals(0, Integer.rotateRight(0, 4));
assertEquals(Integer.MIN_VALUE, Integer.rotateRight(1, 1));
assertEquals(0x10000000, Integer.rotateRight(1, 4));
assertEquals(-1, Integer.rotateRight(-1, 4));
assertEquals(Integer.MIN_VALUE, Integer.rotateLeft(Integer.MIN_VALUE, 0));
assertEquals(1, Integer.rotateRight(Integer.MIN_VALUE, -1));
assertEquals(-1, Integer.rotateRight(-1, 1000));
}

public void testSignum() {
Expand Down
6 changes: 6 additions & 0 deletions user/test/com/google/gwt/emultest/java/lang/LongTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,19 @@ public void testRotateLeft() {
assertEquals(-1, Long.rotateLeft(-1, 4));
assertEquals(Long.MIN_VALUE, Long.rotateLeft(0x4000000000000000L, 1));
assertEquals(1, Long.rotateLeft(Long.MIN_VALUE, 1));
assertEquals(Long.MIN_VALUE, Long.rotateLeft(Long.MIN_VALUE, 0));
assertEquals(Long.MIN_VALUE, Long.rotateLeft(1, -1));
assertEquals(-1, Long.rotateLeft(-1, 1000));
}

public void testRotateRight() {
assertEquals(0, Long.rotateRight(0, 4));
assertEquals(Long.MIN_VALUE, Long.rotateRight(1, 1));
assertEquals(0x1000000000000000L, Long.rotateRight(1, 4));
assertEquals(-1, Long.rotateRight(-1, 4));
assertEquals(Long.MIN_VALUE, Long.rotateRight(Long.MIN_VALUE, 0));
assertEquals(1, Long.rotateRight(Long.MIN_VALUE, -1));
assertEquals(-1, Long.rotateRight(-1, 1000));
}

public void testSignum() {
Expand Down
Loading