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

Commits on Jul 10, 2017

  1. Copy the full SHA
    933c5ea View commit details
  2. Copy the full SHA
    37a8c63 View commit details
  3. Copy the full SHA
    36e97c6 View commit details
5 changes: 2 additions & 3 deletions core/src/main/java/org/jruby/RubyFloat.java
Original file line number Diff line number Diff line change
@@ -180,9 +180,8 @@ public RubyFloat convertToFloat() {
return this;
}

protected int compareValue(RubyNumeric other) {
double otherVal = other.getDoubleValue();
return getValue() > otherVal ? 1 : getValue() < otherVal ? -1 : 0;
public int signum() {
return (int) Math.signum(value); // NOTE: (int) NaN ?
}

public static RubyFloat newFloat(Ruby runtime, double value) {
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/RubyNumeric.java
Original file line number Diff line number Diff line change
@@ -189,9 +189,9 @@ private static void tooBig(IRubyObject arg, long num) {
*/
public static byte num2chr(IRubyObject arg) {
if (arg instanceof RubyString) {
String value = arg.toString();

if (value != null && value.length() > 0) return (byte) value.charAt(0);
if (((RubyString) arg).size() > 0) {
return (byte) ((RubyString) arg).getByteList().get(0);
}
}

return (byte) num2int(arg);
26 changes: 20 additions & 6 deletions core/src/main/java/org/jruby/RubyRange.java
Original file line number Diff line number Diff line change
@@ -301,8 +301,8 @@ public RubyFixnum hash(ThreadContext context) {
return context.runtime.newFixnum(hash);
}

private IRubyObject inspectValue(final ThreadContext context, IRubyObject value) {
return context.safeRecurse(INSPECT_RECURSIVE, value, value, "inspect", true);
private static RubyString inspectValue(final ThreadContext context, IRubyObject value) {
return (RubyString) context.safeRecurse(INSPECT_RECURSIVE, value, value, "inspect", true);
}

private static class InspectRecursive implements ThreadContext.RecursiveFunctionEx<IRubyObject> {
@@ -319,20 +319,34 @@ public IRubyObject call(ThreadContext context, IRubyObject state, IRubyObject ob

private static final byte[] DOTDOTDOT = new byte[]{'.', '.', '.'};

@Override
public IRubyObject inspect() {
return inspect(getRuntime().getCurrentContext());
}

@JRubyMethod(name = "inspect")
public IRubyObject inspect(final ThreadContext context) {
RubyString i1 = ((RubyString) inspectValue(context, begin)).strDup(context.runtime);
RubyString i2 = (RubyString) inspectValue(context, end);
public RubyString inspect(final ThreadContext context) {
RubyString i1 = inspectValue(context, begin).strDup(context.runtime);
RubyString i2 = inspectValue(context, end);
i1.cat(DOTDOTDOT, 0, isExclusive ? 3 : 2);
i1.append(i2);
i1.infectBy(i2);
i1.infectBy(this);
return i1;
}

@Override
public IRubyObject to_s() {
return to_s(getRuntime());
}

@JRubyMethod(name = "to_s")
public IRubyObject to_s(final ThreadContext context) {
RubyString i1 = begin.asString().strDup(context.runtime);
return to_s(context.runtime);
}

private RubyString to_s(final Ruby runtime) {
RubyString i1 = begin.asString().strDup(runtime);
RubyString i2 = end.asString();
i1.cat(DOTDOTDOT, 0, isExclusive ? 3 : 2);
i1.append(i2);
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/util/Numeric.java
Original file line number Diff line number Diff line change
@@ -68,7 +68,7 @@ public static IRubyObject f_cmp(ThreadContext context, IRubyObject x, IRubyObjec
*
*/
public static IRubyObject f_div(ThreadContext context, IRubyObject x, IRubyObject y) {
if (y instanceof RubyFixnum && ((RubyFixnum)y).getLongValue() == 1) return x;
if (y instanceof RubyFixnum && ((RubyFixnum) y).getLongValue() == 1) return x;
return sites(context).op_quo.call(context, x, x, y);
}

@@ -343,6 +343,7 @@ public static boolean f_negative_p(ThreadContext context, IRubyObject x) {
*/
public static boolean f_zero_p(ThreadContext context, IRubyObject x) {
if (x instanceof RubyInteger) return ((RubyInteger) x).signum() == 0;
if (x instanceof RubyFloat) return ((RubyFloat) x).signum() == 0;
return sites(context).op_equals.call(context, x, x, RubyFixnum.zero(context.runtime)).isTrue();
}