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: 1d8dc060dc35
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: c83f08995cbe
Choose a head ref
  • 2 commits
  • 1 file changed
  • 2 contributors

Commits on Mar 30, 2015

  1. 1
    Copy the full SHA
    166f6fe View commit details
  2. Merge pull request #2782 from bjfish/truffle_fixnum_abs_fix

    [Truffle] Adding overflow specializations for Fixnum#abs.
    chrisseaton committed Mar 30, 2015
    Copy the full SHA
    c83f089 View commit details
Showing with 23 additions and 7 deletions.
  1. +23 −7 truffle/src/main/java/org/jruby/truffle/nodes/core/FixnumNodes.java
Original file line number Diff line number Diff line change
@@ -1395,7 +1395,7 @@ public Object rightShiftFallback(VirtualFrame frame, Object a, Object b) {

}

@CoreMethod(names = { "abs", "magnitude" })
@CoreMethod(names = {"abs", "magnitude"})
public abstract static class AbsNode extends CoreMethodNode {

public AbsNode(RubyContext context, SourceSection sourceSection) {
@@ -1406,14 +1406,30 @@ public AbsNode(AbsNode prev) {
super(prev);
}

@Specialization
public int abs(int n) {
return Math.abs(n);
@Specialization(rewriteOn = ArithmeticException.class)
public int absIntInBounds(int n) {
return (n < 0) ? ExactMath.subtractExact(0, n) : n;
}

@Specialization
public long abs(long n) {
return Math.abs(n);
@Specialization(contains = "absIntInBounds")
public Object abs(int n) {
if (n == Integer.MIN_VALUE) {
return -((long) n);
}
return (n < 0) ? -n : n;
}

@Specialization(rewriteOn = ArithmeticException.class)
public long absInBounds(long n) {
return (n < 0) ? ExactMath.subtractExact(0, n) : n;
}

@Specialization(contains = "absInBounds")
public Object abs(long n) {
if (n == Long.MIN_VALUE) {
return new RubyBignum(getContext().getCoreLibrary().getBignumClass(), BigInteger.valueOf(n).abs());
}
return (n < 0) ? -n : n;
}

}