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

Commits on Jan 23, 2018

  1. Implement Rational#coerce with Complex object

    In MRI
    
    * if the argument is complex with zero imaginary part,
      converts it to ratinal
    * if the argument is complex with non-zero imaginary part,
      converts self to complex
    
    Ref: https://github.com/ruby/ruby/blob/v2_3_0/rational.c#L1171
    yui-knk committed Jan 23, 2018
    Copy the full SHA
    f1b16b2 View commit details
  2. Copy the full SHA
    99a3ead View commit details
  3. Merge pull request #5001 from yui-knk/rational_coerce_with_complex

    Implement `Rational#coerce` with `Complex` object
    enebo authored Jan 23, 2018

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    ba67802 View commit details
Showing with 7 additions and 1 deletion.
  1. +7 −0 core/src/main/java/org/jruby/RubyRational.java
  2. +0 −1 test/mri/excludes/Rational_Test.rb
7 changes: 7 additions & 0 deletions core/src/main/java/org/jruby/RubyRational.java
Original file line number Diff line number Diff line change
@@ -712,6 +712,13 @@ public IRubyObject op_coerce(ThreadContext context, IRubyObject other) {
return runtime.newArray(other, f_to_f(context, this));
} else if (other instanceof RubyRational) {
return runtime.newArray(other, this);
} else if (other instanceof RubyComplex) {
RubyComplex otherComplex = (RubyComplex)other;
if (k_exact_p(otherComplex.getImage()) && f_zero_p(context, otherComplex.getImage())) {
return runtime.newArray(RubyRational.newRationalBang(context, getMetaClass(), otherComplex.getReal()), this);
} else {
return runtime.newArray(other, RubyComplex.newComplexCanonicalize(context, this));
}
}
throw runtime.newTypeError(other.getMetaClass() + " can't be coerced into " + getMetaClass());
}
1 change: 0 additions & 1 deletion test/mri/excludes/Rational_Test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
exclude :test_coerce, "needs investigation"
exclude :test_coerce2, "needs investigation"
exclude :test_conv, "needs investigation"
exclude :test_marshal, "needs investigation"