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: 12f3b2c49c03
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0d732f381138
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Nov 22, 2016

  1. Copy the full SHA
    216bc31 View commit details
  2. Copy the full SHA
    0d732f3 View commit details
36 changes: 36 additions & 0 deletions core/src/main/java/org/jruby/RubyComplex.java
Original file line number Diff line number Diff line change
@@ -968,6 +968,42 @@ public IRubyObject rationalize(ThreadContext context, IRubyObject[] args) {
}
return real.callMethod(context, "rationalize", args);
}

@JRubyMethod(name = "finite?")
@Override
public IRubyObject finite_p(ThreadContext context) {
IRubyObject magnitude = magnitude(context);

if (magnitude instanceof RubyInteger || magnitude instanceof RubyRational) {
return context.runtime.getTrue();
}

if (magnitude instanceof RubyFloat) {
return context.runtime.newBoolean(!((RubyFloat) magnitude).infinite_p().isTrue());
}

return sites(context).finite.call(context, magnitude, magnitude);
}

@JRubyMethod(name = "infinite?")
@Override
public IRubyObject infinite_p(ThreadContext context) {
IRubyObject magnitude = magnitude(context);

if (magnitude instanceof RubyInteger || magnitude instanceof RubyRational) {
return context.nil;
}

if (magnitude instanceof RubyFloat) {
RubyFloat flote = (RubyFloat) magnitude;
if (flote.infinite_p().isTrue()) {
return context.runtime.newFixnum(flote.getDoubleValue() < 0 ? -1 : 1);
}
return context.nil;
}

return sites(context).infinite.call(context, magnitude, magnitude);
}

static RubyArray str_to_c_internal(ThreadContext context, IRubyObject recv) {
RubyString s = recv.convertToString();
10 changes: 10 additions & 0 deletions core/src/main/java/org/jruby/RubyNumeric.java
Original file line number Diff line number Diff line change
@@ -1357,6 +1357,16 @@ public IRubyObject isPositive(ThreadContext context) {
return sites(context).op_gt.call(context, this, this, zero);
}

@JRubyMethod(name = "finite?")
public IRubyObject finite_p(ThreadContext context) {
return context.runtime.getTrue();
}

@JRubyMethod(name = "infinite?")
public IRubyObject infinite_p(ThreadContext context) {
return context.runtime.getNil();
}

private static JavaSites.NumericSites sites(ThreadContext context) {
return context.sites.Numeric;
}
2 changes: 2 additions & 0 deletions core/src/main/java/org/jruby/runtime/JavaSites.java
Original file line number Diff line number Diff line change
@@ -349,6 +349,8 @@ public static class ComplexSites {
public final CallSite op_exp = new FunctionalCachingCallSite("**");
public final CallSite op_times = new FunctionalCachingCallSite("*");
public final CallSite op_minus = new FunctionalCachingCallSite("-");
public final CallSite finite = new FunctionalCachingCallSite("finite?");
public final CallSite infinite = new FunctionalCachingCallSite("infinite?");
}

public static class RationalSites {
1 change: 1 addition & 0 deletions test/mri/excludes/TestFlip.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
exclude :test_flip_flop, "flip/flop syntax unimplemented in JRuby"
exclude :test_shared_thread, "needs investigation"
exclude :test_shared_eval, "IR already built and possibly fully compiled non-closure scope so we cannot add new flip var nor initialize its flip state by adding instructions"