final RubyInteger op_and(ThreadContext context, RubyFixnum other) { return bignorm(context.runtime, value.and(fix2big(other))); }
final RubyInteger op_and(ThreadContext context, RubyFixnum other) { return bignorm(context.runtime, value.and(fix2big(other))); }
final RubyInteger op_or(ThreadContext context, RubyFixnum other) { return bignorm(context.runtime, value.or(fix2big(other))); // no bignorm here needed }
final RubyInteger op_or(ThreadContext context, RubyFixnum other) { return bignorm(context.runtime, value.or(fix2big(other))); // no bignorm here needed }
/** rb_big_modulo * */ @JRubyMethod(name = {"%", "modulo"}, required = 1, compat = RUBY1_8) public IRubyObject op_mod(ThreadContext context, IRubyObject other) { final BigInteger otherValue; if (other instanceof RubyFixnum) { otherValue = fix2big((RubyFixnum) other); } else if (other instanceof RubyBignum) { otherValue = ((RubyBignum) other).value; } else { return coerceBin(context, "%", other); } Ruby runtime = context.runtime; if (otherValue.signum() == 0) throw runtime.newZeroDivisionError(); BigInteger result = value.mod(otherValue.abs()); if (otherValue.signum() == -1 && result.signum() != 0) result = otherValue.add(result); return bignorm(runtime, result); }
/** rb_big_modulo * */ @JRubyMethod(name = {"%", "modulo"}, required = 1, compat = RUBY1_8) public IRubyObject op_mod(ThreadContext context, IRubyObject other) { final BigInteger otherValue; if (other instanceof RubyFixnum) { otherValue = fix2big((RubyFixnum) other); } else if (other instanceof RubyBignum) { otherValue = ((RubyBignum) other).value; } else { return coerceBin(context, "%", other); } Ruby runtime = context.runtime; if (otherValue.signum() == 0) throw runtime.newZeroDivisionError(); BigInteger result = value.mod(otherValue.abs()); if (otherValue.signum() == -1 && result.signum() != 0) result = otherValue.add(result); return bignorm(runtime, result); }
@JRubyMethod(name = "*", required = 1, compat = RUBY1_9) public IRubyObject op_mul19(ThreadContext context, IRubyObject other) { Ruby runtime = context.runtime; BigInteger result; if (other instanceof RubyFixnum) { return bignorm(runtime, value.multiply(fix2big(((RubyFixnum) other)))); } else if (other instanceof RubyBignum) { return bignorm(runtime, value.multiply(((RubyBignum)other).value)); } else return opMulOther(context, other); }
@JRubyMethod(name = "*", required = 1, compat = RUBY1_9) public IRubyObject op_mul19(ThreadContext context, IRubyObject other) { Ruby runtime = context.runtime; BigInteger result; if (other instanceof RubyFixnum) { return bignorm(runtime, value.multiply(fix2big(((RubyFixnum) other)))); } else if (other instanceof RubyBignum) { return bignorm(runtime, value.multiply(((RubyBignum)other).value)); } else return opMulOther(context, other); }
/** rb_big_mul * */ @JRubyMethod(name = "*", required = 1) public IRubyObject op_mul(ThreadContext context, IRubyObject other) { Ruby runtime = context.runtime; if (other instanceof RubyFixnum) { BigInteger result = value.multiply(fix2big(((RubyFixnum) other))); return result.signum() == 0 ? RubyFixnum.zero(runtime) : new RubyBignum(runtime, result); } if (other instanceof RubyBignum) { BigInteger result = value.multiply(((RubyBignum)other).value); return result.signum() == 0 ? RubyFixnum.zero(runtime) : new RubyBignum(runtime, result); } else return opMulOther(context, other); }
/** rb_big_mul * */ @JRubyMethod(name = "*", required = 1) public IRubyObject op_mul(ThreadContext context, IRubyObject other) { Ruby runtime = context.runtime; if (other instanceof RubyFixnum) { BigInteger result = value.multiply(fix2big(((RubyFixnum) other))); return result.signum() == 0 ? RubyFixnum.zero(runtime) : new RubyBignum(runtime, result); } if (other instanceof RubyBignum) { BigInteger result = value.multiply(((RubyBignum)other).value); return result.signum() == 0 ? RubyFixnum.zero(runtime) : new RubyBignum(runtime, result); } else return opMulOther(context, other); }
/** rb_big_remainder * */ @JRubyMethod(name = "remainder", required = 1, compat = RUBY1_8) @Override public IRubyObject remainder(ThreadContext context, IRubyObject other) { final BigInteger otherValue; if (other instanceof RubyFixnum) { otherValue = fix2big(((RubyFixnum) other)); } else if (other instanceof RubyBignum) { otherValue = ((RubyBignum) other).value; } else { return coerceBin(context, "remainder", other); } Ruby runtime = context.runtime; if (otherValue.signum() == 0) throw runtime.newZeroDivisionError(); return bignorm(runtime, value.remainder(otherValue)); }
/** rb_big_remainder * */ @JRubyMethod(name = "remainder", required = 1, compat = RUBY1_8) @Override public IRubyObject remainder(ThreadContext context, IRubyObject other) { final BigInteger otherValue; if (other instanceof RubyFixnum) { otherValue = fix2big(((RubyFixnum) other)); } else if (other instanceof RubyBignum) { otherValue = ((RubyBignum) other).value; } else { return coerceBin(context, "remainder", other); } Ruby runtime = context.runtime; if (otherValue.signum() == 0) throw runtime.newZeroDivisionError(); return bignorm(runtime, value.remainder(otherValue)); }
/** rb_big_eq * */ @Override public IRubyObject op_equal(ThreadContext context, IRubyObject other) { 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) { double a = ((RubyFloat) other).getDoubleValue(); if (Double.isNaN(a)) { return context.fals; } return RubyBoolean.newBoolean(context.runtime, a == big2dbl(this)); } else { return other.op_eqq(context, this); } return RubyBoolean.newBoolean(context.runtime, value.compareTo(otherValue) == 0); }
/** rb_big_eq * */ @Override public IRubyObject op_equal(ThreadContext context, IRubyObject other) { 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) { double a = ((RubyFloat) other).getDoubleValue(); if (Double.isNaN(a)) { return context.fals; } return RubyBoolean.newBoolean(context.runtime, a == big2dbl(this)); } else { return other.op_eqq(context, this); } return RubyBoolean.newBoolean(context.runtime, value.compareTo(otherValue) == 0); }
/** rb_big_and * */ @JRubyMethod(name = "&", required = 1, compat = RUBY1_8) public IRubyObject op_and(ThreadContext context, IRubyObject other) { other = other.convertToInteger(); if (other instanceof RubyBignum) { return bignorm(getRuntime(), value.and(((RubyBignum) other).value)); } else if (other instanceof RubyFixnum) { return bignorm(getRuntime(), value.and(fix2big((RubyFixnum)other))); } return coerceBin(context, "&", other); }
/** rb_big_and * */ @JRubyMethod(name = "&", required = 1, compat = RUBY1_8) public IRubyObject op_and(ThreadContext context, IRubyObject other) { other = other.convertToInteger(); if (other instanceof RubyBignum) { return bignorm(getRuntime(), value.and(((RubyBignum) other).value)); } else if (other instanceof RubyFixnum) { return bignorm(getRuntime(), value.and(fix2big((RubyFixnum)other))); } return coerceBin(context, "&", other); }
/** rb_big_or * */ @JRubyMethod(name = "|", required = 1, compat = RUBY1_8) public IRubyObject op_or(ThreadContext context, IRubyObject other) { other = other.convertToInteger(); if (other instanceof RubyBignum) { return bignorm(getRuntime(), value.or(((RubyBignum) other).value)); } if (other instanceof RubyFixnum) { // no bignorm here needed return bignorm(getRuntime(), value.or(fix2big((RubyFixnum)other))); } return coerceBin(context, "|", other); }
/** rb_big_or * */ @JRubyMethod(name = "|", required = 1, compat = RUBY1_8) public IRubyObject op_or(ThreadContext context, IRubyObject other) { other = other.convertToInteger(); if (other instanceof RubyBignum) { return bignorm(getRuntime(), value.or(((RubyBignum) other).value)); } if (other instanceof RubyFixnum) { // no bignorm here needed return bignorm(getRuntime(), value.or(fix2big((RubyFixnum)other))); } return coerceBin(context, "|", other); }
private IRubyObject powerOther19(ThreadContext context, IRubyObject other) { Ruby runtime = context.runtime; long a = value; if (other instanceof RubyBignum) { if (other.callMethod(context, "<", RubyFixnum.zero(runtime)).isTrue()) { return RubyRational.newRationalRaw(runtime, this).callMethod(context, "**", other); } if (a == 0) return RubyFixnum.zero(runtime); if (a == 1) return RubyFixnum.one(runtime); if (a == -1) { return ((RubyBignum)other).even_p(context).isTrue() ? RubyFixnum.one(runtime) : RubyFixnum.minus_one(runtime); } RubyBignum.newBignum(runtime, RubyBignum.fix2big(this)).op_pow(context, other); } else if (other instanceof RubyFloat) { double b = ((RubyFloat)other).getValue(); if (b == 0.0 || a == 1) return runtime.newFloat(1.0); if (a == 0) return runtime.newFloat(b < 0 ? 1.0 / 0.0 : 0.0); return RubyFloat.newFloat(runtime, Math.pow(a, b)); } return coerceBin(context, "**", other); }
private IRubyObject powerOther19(ThreadContext context, IRubyObject other) { Ruby runtime = context.runtime; long a = value; if (other instanceof RubyBignum) { if (other.callMethod(context, "<", RubyFixnum.zero(runtime)).isTrue()) { return RubyRational.newRationalRaw(runtime, this).callMethod(context, "**", other); } if (a == 0) return RubyFixnum.zero(runtime); if (a == 1) return RubyFixnum.one(runtime); if (a == -1) { return ((RubyBignum)other).even_p(context).isTrue() ? RubyFixnum.one(runtime) : RubyFixnum.minus_one(runtime); } RubyBignum.newBignum(runtime, RubyBignum.fix2big(this)).op_pow(context, other); } else if (other instanceof RubyFloat) { double b = ((RubyFloat)other).getValue(); if (b == 0.0 || a == 1) return runtime.newFloat(1.0); if (a == 0) return runtime.newFloat(b < 0 ? 1.0 / 0.0 : 0.0); return RubyFloat.newFloat(runtime, Math.pow(a, b)); } return coerceBin(context, "**", other); }