Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 25f0e1fa1583
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: aa8f4ae45032
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Sep 14, 2015

  1. Copy the full SHA
    50492b7 View commit details
  2. Copy the full SHA
    aa8f4ae View commit details
Showing with 23 additions and 11 deletions.
  1. +20 −2 spec/ruby/core/fixnum/right_shift_spec.rb
  2. +3 −9 truffle/src/main/java/org/jruby/truffle/nodes/core/fixnum/FixnumNodes.java
22 changes: 20 additions & 2 deletions spec/ruby/core/fixnum/right_shift_spec.rb
Original file line number Diff line number Diff line change
@@ -7,6 +7,8 @@

it "returns n shifted right m bits when n < 0, m > 0" do
(-2 >> 1).should == -1
(-7 >> 1).should == -4
(-42 >> 2).should == -11
end

it "returns n shifted left m bits when n > 0, m < 0" do
@@ -29,8 +31,24 @@
(-1 >> 0).should == -1
end

it "returns 0 when m > 0 and m == p where 2**p > n >= 2**(p-1)" do
(4 >> 3).should == 0
it "returns 0 when n > 0, m > 0 and n < 2**m" do
(3 >> 2).should == 0
(7 >> 3).should == 0
(127 >> 7).should == 0

# To make sure the exponent is not truncated
(7 >> 32).should == 0
(7 >> 64).should == 0
end

it "returns -1 when n < 0, m > 0 and n > -(2**m)" do
(-3 >> 2).should == -1
(-7 >> 3).should == -1
(-127 >> 7).should == -1

# To make sure the exponent is not truncated
(-7 >> 32).should == -1
(-7 >> 64).should == -1
end

fixnum_bits = (Math.log(fixnum_max) / Math.log(2)).to_i
Original file line number Diff line number Diff line change
@@ -36,8 +36,6 @@
@CoreClass(name = "Fixnum")
public abstract class FixnumNodes {

private static final int BITS = 64;

@CoreMethod(names = "-@")
public abstract static class NegNode extends CoreMethodArrayArgumentsNode {

@@ -936,14 +934,12 @@ public RightShiftNode(RubyContext context, SourceSection sourceSection) {
@Specialization
public Object rightShift(VirtualFrame frame, int a, int b) {
if (b > 0) {
if (b >= BITS - 1) {
if (b >= Integer.SIZE - 1) {
if (a < 0) {
return -1;
} else {
return 0;
}
} else if (b == 32) {
return 0;
} else {
return a >> b;
}
@@ -960,14 +956,12 @@ public Object rightShift(VirtualFrame frame, int a, int b) {
@Specialization
public Object rightShift(VirtualFrame frame, int a, long b) {
if (b > 0) {
if (b >= BITS - 1) {
if (b >= Integer.SIZE - 1) {
if (a < 0) {
return -1;
} else {
return 0;
}
} else if (b == 32) {
return 0;
} else {
return a >> b;
}
@@ -984,7 +978,7 @@ public Object rightShift(VirtualFrame frame, int a, long b) {
@Specialization
public Object rightShift(VirtualFrame frame, long a, int b) {
if (b > 0) {
if (b >= BITS - 1) {
if (b >= Long.SIZE - 1) {
if (a < 0) {
return -1;
} else {