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

Commits on Apr 17, 2018

  1. Revert "Missed one call to dbl2num."

    This reverts commit 3b44e76.
    headius committed Apr 17, 2018
    Copy the full SHA
    d72665a View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    522e178 View commit details
  3. Copy the full SHA
    54e5a18 View commit details
  4. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    c95601e View commit details
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.doubleToInteger(runtime, div);
return RubyNumeric.dbl2ival(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.doubleToInteger(runtime, pow);
return RubyNumeric.dbl2ival(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.doubleToInteger(runtime, 1.0 / 0.0);
return b > 0 ? RubyFixnum.zero(runtime) : RubyNumeric.dbl2ival(runtime, 1.0 / 0.0);
}
if (a == 1) {
return RubyFixnum.one(runtime);
23 changes: 9 additions & 14 deletions core/src/main/java/org/jruby/RubyFloat.java
Original file line number Diff line number Diff line change
@@ -185,11 +185,6 @@ 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);
}
@@ -416,7 +411,7 @@ public IRubyObject divmod(ThreadContext context, IRubyObject other) {
mod += y;
}
final Ruby runtime = getRuntime();
IRubyObject car = doubleToInteger(runtime, div);
IRubyObject car = dbl2ival(runtime, div);
RubyFloat cdr = RubyFloat.newFloat(runtime, mod);
return RubyArray.newArray(runtime, car, cdr);
default:
@@ -722,7 +717,7 @@ public IRubyObject truncate() {
if (f > 0.0) f = Math.floor(f);
if (f < 0.0) f = Math.ceil(f);

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

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

Ruby runtime = context.runtime;

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


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

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

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

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

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

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

19 changes: 7 additions & 12 deletions core/src/main/java/org/jruby/RubyNumeric.java
Original file line number Diff line number Diff line change
@@ -232,14 +232,14 @@ private static long float2long(RubyFloat flt) {
}
}

/**
* 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.
public static IRubyObject dbl2num(Ruby runtime, double val) {
return RubyFloat.newFloat(runtime, val);
}

/** rb_dbl2big + LONG2FIX at once (numeric.c)
*
* @see RubyFloat#newFloat(Ruby, double)
*/
public static IRubyObject doubleToInteger(Ruby runtime, double val) {
public static IRubyObject dbl2ival(Ruby runtime, double val) {
if (Double.isInfinite(val)) {
throw runtime.newFloatDomainError(val < 0 ? "-Infinity" : "Infinity");
}
@@ -992,7 +992,7 @@ private boolean scanStepArgs(ThreadContext context, IRubyObject[] args, IRubyObj
}
desc = numStepNegative(context, runtime, step);
if (to.isNil()) {
newArgs[0] = to = desc ? RubyFloat.newFloat(runtime, Double.NEGATIVE_INFINITY) : RubyFloat.newFloat(runtime, Double.POSITIVE_INFINITY);
newArgs[0] = to = desc ? dbl2num(runtime, Double.NEGATIVE_INFINITY) : dbl2num(runtime, Double.POSITIVE_INFINITY);
}
return desc;
}
@@ -1421,9 +1421,4 @@ 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.doubleToInteger(arg.getRuntime(),((RubyFloat)arg).getValue());
arg = RubyNumeric.dbl2ival(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.doubleToInteger(context.runtime, value);
return RubyNumeric.dbl2ival(context.runtime, value);
}
} else if (val instanceof RubyFixnum || val instanceof RubyBignum) {
if (base != 0) raiseIntegerBaseError(context);