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

Commits on Jan 23, 2018

  1. Copy the full SHA
    cfd1db2 View commit details
  2. Copy the full SHA
    dff5e8b View commit details
  3. Copy the full SHA
    ccd3809 View commit details
  4. Copy the full SHA
    545f045 View commit details
  5. Copy the full SHA
    1b3c705 View commit details
  6. Copy the full SHA
    54ea604 View commit details
  7. Copy the full SHA
    6c865a5 View commit details
  8. Copy the full SHA
    16988b6 View commit details
28 changes: 19 additions & 9 deletions core/src/main/java/org/jruby/RubyBignum.java
Original file line number Diff line number Diff line change
@@ -597,34 +597,30 @@ public IRubyObject idiv(ThreadContext context, long other) {
/** rb_big_divmod
*
*/
@Override
@JRubyMethod(name = "divmod", required = 1)
public IRubyObject divmod(ThreadContext context, IRubyObject other) {
if (!other.isNil() && other instanceof RubyFloat
&& ((RubyFloat)other).getDoubleValue() == 0) {
throw context.runtime.newZeroDivisionError();
}

Ruby runtime = context.runtime;

final BigInteger otherValue;
if (other instanceof RubyFixnum) {
otherValue = fix2big((RubyFixnum) other);
} else if (other instanceof RubyBignum) {
otherValue = ((RubyBignum) other).value;
} else {
if (other instanceof RubyFloat && ((RubyFloat)other).getDoubleValue() == 0) {
throw runtime.newZeroDivisionError();
throw context.runtime.newZeroDivisionError();
}
return coerceBin(context, sites(context).divmod, other);
}

if (otherValue.signum() == 0) throw runtime.newZeroDivisionError();
if (otherValue.signum() == 0) throw context.runtime.newZeroDivisionError();

BigInteger[] results = value.divideAndRemainder(otherValue);
if ((value.signum() * otherValue.signum()) == -1 && results[1].signum() != 0) {
results[0] = results[0].subtract(BigInteger.ONE);
results[1] = otherValue.add(results[1]);
}

Ruby runtime = context.runtime;
return RubyArray.newArray(runtime, bignorm(runtime, results[0]), bignorm(runtime, results[1]));
}

@@ -933,6 +929,15 @@ public final int compareTo(IRubyObject other) {
return (int)coerceCmp(context, sites(context).op_cmp, other).convertToInteger().getLongValue();
}

@Override
public boolean equals(Object other) {
if (other == this) return true;
if (other instanceof RubyBignum) {
return value.compareTo(((RubyBignum) other).value) == 0;
}
return false;
}

/** rb_big_cmp
*
*/
@@ -1002,6 +1007,11 @@ public RubyFixnum hash() {
return getRuntime().newFixnum(value.hashCode());
}

@Override
public int hashCode() {
return value.hashCode();
}

/** rb_big_to_f
*
*/
Loading