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

Commits on Jul 25, 2017

  1. Copy the full SHA
    4b13469 View commit details
  2. Copy the full SHA
    637ca8a View commit details
Showing with 13 additions and 10 deletions.
  1. +13 −10 core/src/main/java/org/jruby/RubyRational.java
23 changes: 13 additions & 10 deletions core/src/main/java/org/jruby/RubyRational.java
Original file line number Diff line number Diff line change
@@ -823,7 +823,7 @@ public IRubyObject floor(ThreadContext context, IRubyObject n) {

// MRI: nurat_floor
private IRubyObject mriFloor(ThreadContext context) {
return num.op_idiv(context, den);
return num.idiv(context, den);
}

/**
@@ -842,7 +842,7 @@ public IRubyObject ceil(ThreadContext context, IRubyObject n) {

// MRI: nurat_ceil
private IRubyObject mriCeil(ThreadContext context) {
return ((RubyInteger) ((RubyInteger) num.op_uminus()).op_idiv(context, den)).op_uminus();
return ((RubyInteger) ((RubyInteger) num.op_uminus()).idiv(context, den)).op_uminus();
}

@JRubyMethod(name = "to_i")
@@ -865,9 +865,9 @@ public IRubyObject truncate(ThreadContext context, IRubyObject n) {

private IRubyObject mriTruncate(ThreadContext context) {
if (num.isNegative(context).isTrue()) {
return ((RubyInteger) ((RubyInteger) num.op_uminus()).op_idiv(context, den)).op_uminus();
return ((RubyInteger) ((RubyInteger) num.op_uminus()).idiv(context, den)).op_uminus();
}
return num.op_idiv(context, den);
return num.idiv(context, den);
}

@JRubyMethod(name = "round")
@@ -920,21 +920,24 @@ private IRubyObject roundCommon(ThreadContext context, IRubyObject n, RoundingMo
s = this.op_mul(context, b);

if (s instanceof RubyFloat) {
if (((RubyFloat) n).getDoubleValue() < 0.0) {
if (((RubyInteger) n).isNegative(context).isTrue()) {
return RubyFixnum.zero(runtime);
}
return this;
}

RubyClass metaClass = getMetaClass();
RubyFixnum one = RubyFixnum.one(runtime);
if (!(s instanceof RubyRational)) {
s = RubyRational.newRational(context, getMetaClass(), s, RubyFixnum.one(runtime));
s = RubyRational.newRational(context, metaClass, s, one);
}

s = ((RubyRational) s).doRound(context, mode);

s = RubyRational.newRational(context, getMetaClass(), s, RubyFixnum.one(runtime));
s = RubyRational.newRational(context, metaClass, s, one);
s = ((RubyRational) s).op_div(context, b);

if (s instanceof RubyRational && ((RubyInteger) n).op_cmp(context, RubyFixnum.one(runtime)).convertToInteger().getLongValue() < 0) {
if (s instanceof RubyRational && ((RubyInteger) n).op_cmp(context, one).convertToInteger().getLongValue() < 0) {
s = ((RubyRational) s).truncate(context);
}

@@ -976,7 +979,7 @@ private IRubyObject roundHalfDown(ThreadContext context) {
num = (RubyInteger) ((RubyInteger) num.op_mul(context, RubyFixnum.two(runtime))).op_plus(context, den);
num = (RubyInteger) num.op_minus(context, RubyFixnum.one(runtime));
den = (RubyInteger) den.op_mul(context, RubyFixnum.two(runtime));
num = (RubyInteger) num.op_idiv(context, den);
num = (RubyInteger) num.idiv(context, den);

if (neg.isTrue())
num = (RubyInteger) num.op_uminus();
@@ -1028,7 +1031,7 @@ private IRubyObject roundHalfUp(ThreadContext context) {

num = (RubyInteger) ((RubyInteger) num.op_mul(context, RubyFixnum.two(runtime))).op_plus(context, den);
den = (RubyInteger) den.op_mul(context, RubyFixnum.two(runtime));
num = (RubyInteger) num.op_idiv(context, den);
num = (RubyInteger) num.idiv(context, den);

if (neg.isTrue()) {
num = (RubyInteger) num.op_uminus();