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

Commits on Jan 25, 2018

  1. Fix convertCommon

    1. Remove f_to_r call
      MRI does not call `to_r` when `a1` is not a float nor a string.
      Ref: https://github.com/ruby/ruby/blob/v2_3_0/rational.c#L2423-L2428
    
    2. Call `#to_r` when `a1` is an integer
      Ref: https://github.com/ruby/ruby/blob/v2_3_0/rational.c#L2445-L2446
    yui-knk committed Jan 25, 2018
    Copy the full SHA
    ca0f447 View commit details

Commits on Jan 26, 2018

  1. Fix spec:ruby:fast

    yui-knk committed Jan 26, 2018
    Copy the full SHA
    436527f View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    ca984cb View commit details
  3. Merge pull request #5010 from yui-knk/rational_convert

    Fix `convertCommon`
    enebo authored Jan 26, 2018
    Copy the full SHA
    d26cad1 View commit details
Showing with 8 additions and 9 deletions.
  1. +5 −4 core/src/main/java/org/jruby/RubyNumeric.java
  2. +3 −5 core/src/main/java/org/jruby/RubyRational.java
9 changes: 5 additions & 4 deletions core/src/main/java/org/jruby/RubyNumeric.java
Original file line number Diff line number Diff line change
@@ -61,6 +61,7 @@
import static org.jruby.util.Numeric.f_arg;
import static org.jruby.util.Numeric.f_mul;
import static org.jruby.util.Numeric.f_negative_p;
import static org.jruby.util.Numeric.f_to_r;

/**
* Base class for all numerical types in ruby.
@@ -1183,21 +1184,21 @@ protected final IRubyObject op_num_equal(ThreadContext context, IRubyObject othe
return sites(context).op_equals.call(context, other, other, this);
}

/** num_numerator
/** numeric_numerator
*
*/
@JRubyMethod(name = "numerator")
public IRubyObject numerator(ThreadContext context) {
IRubyObject rational = RubyRational.newRationalConvert(context, this);
IRubyObject rational = f_to_r(context, this);
return sites(context).numerator.call(context, rational, rational);
}

/** num_denominator
/** numeric_denominator
*
*/
@JRubyMethod(name = "denominator")
public IRubyObject denominator(ThreadContext context) {
IRubyObject rational = RubyRational.newRationalConvert(context, this);
IRubyObject rational = f_to_r(context, this);
return sites(context).denominator.call(context, rational, rational);
}

8 changes: 3 additions & 5 deletions core/src/main/java/org/jruby/RubyRational.java
Original file line number Diff line number Diff line change
@@ -365,10 +365,6 @@ private static IRubyObject convertCommon(ThreadContext context, IRubyObject recv
a1 = f_to_r(context, a1);
} else if (a1 instanceof RubyString) {
a1 = str_to_r_strict(context, a1);
} else {
if (a1 instanceof RubyObject && responds_to_to_r(context, a1)) {
a1 = f_to_r(context, a1);
}
}

if (a2 instanceof RubyFloat) {
@@ -382,7 +378,9 @@ private static IRubyObject convertCommon(ThreadContext context, IRubyObject recv
}

if (a2.isNil()) {
if (a1 instanceof RubyNumeric && !f_integer_p(context, a1).isTrue()) return a1;
if (!(a1 instanceof RubyNumeric && f_integer_p(context, a1).isTrue())) {
return TypeConverter.convertToType(a1, context.getRuntime().getRational(), "to_r");
}
return newInstance(context, recv, a1);
} else {
if (a1 instanceof RubyNumeric && a2 instanceof RubyNumeric &&