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

Commits on Feb 28, 2018

  1. Copy the full SHA
    20e2eb2 View commit details
  2. Copy the full SHA
    52fbb08 View commit details
Showing with 23 additions and 50 deletions.
  1. +1 −1 core/src/main/java/org/jruby/RubyArray.java
  2. +6 −13 core/src/main/java/org/jruby/RubyNumeric.java
  3. +16 −36 core/src/main/java/org/jruby/RubyRational.java
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyArray.java
Original file line number Diff line number Diff line change
@@ -334,7 +334,7 @@ public static RubyArray newArrayMayCopy(Ruby runtime, IRubyObject[] args, int st
return newArrayNoCopy(runtime, args, start, length);
}

public static RubyArray newArrayNoCopy(Ruby runtime, IRubyObject[] args) {
public static RubyArray newArrayNoCopy(Ruby runtime, IRubyObject... args) {
return new RubyArray(runtime, args);
}

19 changes: 6 additions & 13 deletions core/src/main/java/org/jruby/RubyNumeric.java
Original file line number Diff line number Diff line change
@@ -136,31 +136,24 @@ public static RoundingMode getRoundingMode(ThreadContext context, IRubyObject op
throw context.runtime.newArgumentError("invalid rounding mode: " + halfArg);
}

// The implementations of these are all bonus (see TODO above) I was going
// to throw an error from these, but it appears to be the wrong place to
// do it.
public double getDoubleValue() {
return 0;
}
// The implementations of these are all bonus (see above)

/**
* Return the value of this numeric as a 64-bit long. If the value does not
* fit in 64 bits, it will be truncated.
*/
public long getLongValue() {
return 0;
}
public long getLongValue() { return 0; }

/**
* Return the value of this numeric as a 32-bit long. If the value does not
* fit in 32 bits, it will be truncated.
*/
public int getIntValue() {
return 0;
}
public int getIntValue() { return (int) getLongValue(); }

public double getDoubleValue() { return getLongValue(); }

public BigInteger getBigIntegerValue() {
return BigInteger.ZERO;
return BigInteger.valueOf(getLongValue());
}

public static RubyNumeric newNumeric(Ruby runtime) {
52 changes: 16 additions & 36 deletions core/src/main/java/org/jruby/RubyRational.java
Original file line number Diff line number Diff line change
@@ -25,39 +25,8 @@
***** END LICENSE BLOCK *****/
package org.jruby;

import static org.jruby.util.Numeric.f_abs;
import static org.jruby.util.Numeric.f_add;
import static org.jruby.util.Numeric.f_cmp;
import static org.jruby.util.Numeric.f_div;
import static org.jruby.util.Numeric.f_equal;
import static org.jruby.util.Numeric.f_expt;
import static org.jruby.util.Numeric.f_floor;
import static org.jruby.util.Numeric.f_gcd;
import static org.jruby.util.Numeric.f_idiv;
import static org.jruby.util.Numeric.f_integer_p;
import static org.jruby.util.Numeric.f_minus_one_p;
import static org.jruby.util.Numeric.f_mul;
import static org.jruby.util.Numeric.f_negate;
import static org.jruby.util.Numeric.f_negative_p;
import static org.jruby.util.Numeric.f_odd_p;
import static org.jruby.util.Numeric.f_one_p;
import static org.jruby.util.Numeric.f_rshift;
import static org.jruby.util.Numeric.f_sub;
import static org.jruby.util.Numeric.f_to_f;
import static org.jruby.util.Numeric.f_to_i;
import static org.jruby.util.Numeric.f_to_r;
import static org.jruby.util.Numeric.f_truncate;
import static org.jruby.util.Numeric.f_xor;
import static org.jruby.util.Numeric.f_zero_p;
import static org.jruby.util.Numeric.i_gcd;
import static org.jruby.util.Numeric.i_ilog2;
import static org.jruby.util.Numeric.k_exact_p;
import static org.jruby.util.Numeric.k_integer_p;
import static org.jruby.util.Numeric.k_numeric_p;
import static org.jruby.util.Numeric.ldexp;
import static org.jruby.util.Numeric.nurat_rationalize_internal;

import java.io.IOException;
import java.math.BigInteger;
import java.math.RoundingMode;

import org.jcodings.specific.ASCIIEncoding;
@@ -83,6 +52,7 @@

import static org.jruby.runtime.Helpers.invokedynamic;
import static org.jruby.runtime.invokedynamic.MethodNames.HASH;
import static org.jruby.util.Numeric.*;

/**
* rational.c (as of revision: 20011)
@@ -375,7 +345,7 @@ public static IRubyObject convert(ThreadContext context, IRubyObject recv, IRuby
return convertCommon(context, (RubyClass) recv, a1, a2);
}

private static IRubyObject convertCommon(ThreadContext context, RubyClass clazz, IRubyObject a1, IRubyObject a2) {
private static RubyNumeric convertCommon(ThreadContext context, RubyClass clazz, IRubyObject a1, IRubyObject a2) {
if (a1 instanceof RubyComplex) {
RubyComplex a1c = (RubyComplex) a1;
if (k_exact_p(a1c.getImage()) && f_zero_p(context, a1c.getImage())) a1 = a1c.getReal();
@@ -406,18 +376,18 @@ private static IRubyObject convertCommon(ThreadContext context, RubyClass clazz,
}

if (a1 instanceof RubyRational) {
if (a2 == context.nil || (k_exact_p(a2) && f_one_p(context, a2))) return a1;
if (a2 == context.nil || (k_exact_p(a2) && f_one_p(context, a2))) return (RubyRational) a1;
}

if (a2 == context.nil) {
if (!(a1 instanceof RubyNumeric && f_integer_p(context, (RubyNumeric) a1))) {
return TypeConverter.convertToType(context, a1, context.runtime.getRational(), sites(context).to_r_checked);
return (RubyRational) TypeConverter.convertToType(context, a1, context.runtime.getRational(), sites(context).to_r_checked);
}
return newInstance(context, clazz, a1);
} else {
if ((a1 instanceof RubyNumeric && a2 instanceof RubyNumeric) &&
(!f_integer_p(context, (RubyNumeric) a1) || !f_integer_p(context, (RubyNumeric) a2))) {
return f_div(context, a1, a2);
return (RubyNumeric) f_div(context, a1, a2);
}
return newInstance(context, clazz, a1, a2);
}
@@ -947,6 +917,16 @@ public IRubyObject to_i(ThreadContext context) {
return mriTruncate(context); // truncate(context);
}

@Override
public long getLongValue() {
return convertToInteger().getLongValue();
}

@Override
public BigInteger getBigIntegerValue() {
return convertToInteger().getBigIntegerValue();
}

/**
* MRI: nurat_truncate
*/