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

Commits on Apr 16, 2018

  1. Copy the full SHA
    462c075 View commit details
  2. Copy the full SHA
    52cc063 View commit details
  3. Copy the full SHA
    a0b93c1 View commit details
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/AbstractRubyMethod.java
Original file line number Diff line number Diff line change
@@ -100,7 +100,7 @@ public String getMethodName() {

@JRubyMethod(name = "owner")
public IRubyObject owner(ThreadContext context) {
return method.getRealMethod().getDefinedClass();
return implementationModule;
}

@JRubyMethod(name = "source_location")
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/RubyBignum.java
Original file line number Diff line number Diff line change
@@ -420,7 +420,7 @@ private IRubyObject op_divide(ThreadContext context, IRubyObject other, boolean
if (slash) {
return RubyFloat.newFloat(runtime, div);
} else {
return RubyNumeric.dbl2num(runtime, div);
return RubyNumeric.doubleToInteger(runtime, div);
}
} else {
return coerceBin(context, slash ? sites(context).op_quo : sites(context).div, other);
@@ -634,7 +634,7 @@ public IRubyObject op_pow19(ThreadContext context, IRubyObject other) {
if (Double.isInfinite(pow)) {
return RubyFloat.newFloat(runtime, pow);
}
return RubyNumeric.dbl2num(runtime, pow);
return RubyNumeric.doubleToInteger(runtime, pow);
}

/** rb_big_and
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyFixnum.java
Original file line number Diff line number Diff line change
@@ -815,7 +815,7 @@ private IRubyObject powerFixnum19(ThreadContext context, IRubyObject other) {
return this;
}
if (a == 0) {
return b > 0 ? RubyFixnum.zero(runtime) : RubyNumeric.dbl2num(runtime, 1.0 / 0.0);
return b > 0 ? RubyFixnum.zero(runtime) : RubyNumeric.doubleToInteger(runtime, 1.0 / 0.0);
}
if (a == 1) {
return RubyFixnum.one(runtime);
23 changes: 14 additions & 9 deletions core/src/main/java/org/jruby/RubyFloat.java
Original file line number Diff line number Diff line change
@@ -185,6 +185,11 @@ protected int compareValue(RubyNumeric other) {
return getValue() > otherVal ? 1 : getValue() < otherVal ? -1 : 0;
}

/**
* Construct a new Float object from the given double.
*
* MRI: DBL2NUM, rb_float_new
*/
public static RubyFloat newFloat(Ruby runtime, double value) {
return new RubyFloat(runtime, value);
}
@@ -411,7 +416,7 @@ public IRubyObject divmod(ThreadContext context, IRubyObject other) {
mod += y;
}
final Ruby runtime = getRuntime();
IRubyObject car = dbl2num(runtime, div);
IRubyObject car = doubleToInteger(runtime, div);
RubyFloat cdr = RubyFloat.newFloat(runtime, mod);
return RubyArray.newArray(runtime, car, cdr);
default:
@@ -717,7 +722,7 @@ public IRubyObject truncate() {
if (f > 0.0) f = Math.floor(f);
if (f < 0.0) f = Math.ceil(f);

return dbl2num(getRuntime(), f);
return doubleToInteger(getRuntime(), f);
}

/** flo_numerator
@@ -756,7 +761,7 @@ public IRubyObject to_r(ThreadContext context) {

Ruby runtime = context.runtime;

IRubyObject rf = RubyNumeric.dbl2num(runtime, f);
IRubyObject rf = RubyNumeric.doubleToInteger(runtime, f);
IRubyObject rn = RubyFixnum.newFixnum(runtime, n);
return f_mul(context, rf, f_expt(context, RubyFixnum.newFixnum(runtime, FLT_RADIX), rn));
}
@@ -786,7 +791,7 @@ public IRubyObject rationalize(ThreadContext context, IRubyObject[] args) {
long n = exp[0] - DBL_MANT_DIG;


IRubyObject rf = RubyNumeric.dbl2num(runtime, f);
IRubyObject rf = RubyNumeric.doubleToInteger(runtime, f);
IRubyObject rn = RubyFixnum.newFixnum(runtime, n);

if (f_zero_p(context, rf) || !(f_negative_p(context, rn) || f_zero_p(context, rn)))
@@ -817,7 +822,7 @@ public IRubyObject rationalize(ThreadContext context, IRubyObject[] args) {
@JRubyMethod(name = "floor")
@Override
public IRubyObject floor() {
return dbl2num(getRuntime(), Math.floor(value));
return doubleToInteger(getRuntime(), Math.floor(value));
}

/** flo_ceil
@@ -826,15 +831,15 @@ public IRubyObject floor() {
@JRubyMethod(name = "ceil")
@Override
public IRubyObject ceil() {
return dbl2num(getRuntime(), Math.ceil(value));
return doubleToInteger(getRuntime(), Math.ceil(value));
}

/** flo_round
*
*/
@Override
public IRubyObject round() {
return dbl2num(getRuntime(), val2dbl());
return doubleToInteger(getRuntime(), val2dbl());
}

@JRubyMethod(name = "round", optional = 1)
@@ -869,7 +874,7 @@ public IRubyObject round(ThreadContext context, IRubyObject[] args) {
return RubyFloat.newFloat(context.runtime, number);
}
if (digits < -(binexp > 0 ? binexp / 3 + 1 : binexp / 4)) {
return dbl2num(context.runtime, (long) 0);
return doubleToInteger(context.runtime, (long) 0);
}

if (Double.isInfinite(magnifier)) {
@@ -898,7 +903,7 @@ public IRubyObject round(ThreadContext context, IRubyObject[] args) {
BigDecimal roundedNumber = new BigDecimal(Double.toString(number));
return RubyBignum.newBignum(context.runtime, roundedNumber.toBigInteger());
}
return dbl2num(context.runtime, (long)number);
return doubleToInteger(context.runtime, (long)number);
}
}

5 changes: 0 additions & 5 deletions core/src/main/java/org/jruby/RubyMethod.java
Original file line number Diff line number Diff line change
@@ -281,11 +281,6 @@ public IRubyObject receiver(ThreadContext context) {
return receiver;
}

@JRubyMethod
public IRubyObject owner(ThreadContext context) {
return implementationModule;
}

@JRubyMethod
public IRubyObject source_location(ThreadContext context) {
Ruby runtime = context.runtime;
15 changes: 12 additions & 3 deletions core/src/main/java/org/jruby/RubyNumeric.java
Original file line number Diff line number Diff line change
@@ -232,10 +232,14 @@ private static long float2long(RubyFloat flt) {
}
}

/** rb_dbl2big + LONG2FIX at once (numeric.c)
/**
* MRI: rb_dbl2big + LONG2FIX at once (numeric.c)
*
* Note this is NOT equivalent to DBL2NUM in MRI, which largely just constructs a new Float with the given value.
*
* @see RubyFloat#newFloat(Ruby, double)
*/
public static IRubyObject dbl2num(Ruby runtime, double val) {
public static IRubyObject doubleToInteger(Ruby runtime, double val) {
if (Double.isInfinite(val)) {
throw runtime.newFloatDomainError(val < 0 ? "-Infinity" : "Infinity");
}
@@ -988,7 +992,7 @@ private boolean scanStepArgs(ThreadContext context, IRubyObject[] args, IRubyObj
}
desc = numStepNegative(context, runtime, step);
if (to.isNil()) {
newArgs[0] = to = desc ? dbl2num(runtime, Double.NEGATIVE_INFINITY) : dbl2num(runtime, Double.POSITIVE_INFINITY);
newArgs[0] = to = desc ? RubyFloat.newFloat(runtime, Double.NEGATIVE_INFINITY) : doubleToInteger(runtime, Double.POSITIVE_INFINITY);
}
return desc;
}
@@ -1417,4 +1421,9 @@ private static JavaSites.NumericSites sites(ThreadContext context) {
public static RubyFloat str2fnum19(Ruby runtime, RubyString arg, boolean strict) {
return str2fnum(runtime, arg, strict);
}

@Deprecated
public static IRubyObject dbl2num(Ruby runtime, double val) {
return doubleToInteger(runtime, val);
}
}
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/util/Sprintf.java
Original file line number Diff line number Diff line change
@@ -704,7 +704,7 @@ else if ((flags & FLAG_MINUS) != 0) {
if (type != ClassIndex.FIXNUM && type != ClassIndex.BIGNUM) {
switch(type) {
case FLOAT:
arg = RubyNumeric.dbl2num(arg.getRuntime(),((RubyFloat)arg).getValue());
arg = RubyNumeric.doubleToInteger(arg.getRuntime(),((RubyFloat)arg).getValue());
break;
case STRING:
arg = ((RubyString)arg).stringToInum19(0, true);
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/util/TypeConverter.java
Original file line number Diff line number Diff line change
@@ -433,7 +433,7 @@ public static IRubyObject convertToInteger(ThreadContext context, IRubyObject va
double value = ((RubyFloat)val).getValue();
if (value <= RubyFixnum.MAX ||
value >= RubyFixnum.MIN) {
return RubyNumeric.dbl2num(context.runtime, value);
return RubyNumeric.doubleToInteger(context.runtime, value);
}
} else if (val instanceof RubyFixnum || val instanceof RubyBignum) {
if (base != 0) raiseIntegerBaseError(context);