/** rb_big_uminus * */ @Override public IRubyObject op_uminus(ThreadContext context) { return bignorm(context.runtime, value.negate()); }
@Override public RubyInteger op_rshift(ThreadContext context, long shift) { return bignorm(context.runtime, value.shiftRight((int) shift)); }
public IRubyObject decode(Ruby runtime, ByteBuffer enc) { long l = decodeLongBigEndian(enc); return RubyBignum.bignorm(runtime,BigInteger.valueOf(l).and(new BigInteger("FFFFFFFFFFFFFFFF", 16))); }
@Override public final IRubyObject op_plus(ThreadContext context, long other) { BigInteger result = value.add(BigInteger.valueOf(other)); if (other > 0 && value.signum() > 0) return new RubyBignum(context.runtime, result); return bignorm(context.runtime, result); }
@Override public final IRubyObject op_minus(ThreadContext context, long other) { BigInteger result = value.subtract(BigInteger.valueOf(other)); if (value.signum() < 0 && other > 0) return new RubyBignum(context.runtime, result); return bignorm(context.runtime, result); }
public final IRubyObject op_plus(ThreadContext context, BigInteger other) { BigInteger result = value.add(other); if (value.signum() > 0 && other.signum() > 0) return new RubyBignum(context.runtime, result); return bignorm(context.runtime, result); }
public final IRubyObject op_minus(ThreadContext context, BigInteger other) { BigInteger result = value.subtract(other); if (value.signum() < 0 && other.signum() > 0) return new RubyBignum(context.runtime, result); return bignorm(context.runtime, result); }
public final IRubyObject op_plus(ThreadContext context, BigInteger other) { BigInteger result = value.add(other); if (value.signum() > 0 && other.signum() > 0) return new RubyBignum(context.runtime, result); return bignorm(context.runtime, result); }
private RubyInteger divideImpl(Ruby runtime, BigInteger otherValue) { if (otherValue.signum() == 0) throw runtime.newZeroDivisionError(); final BigInteger result; if (value.signum() * otherValue.signum() == -1) { BigInteger[] results = value.divideAndRemainder(otherValue); result = results[1].signum() != 0 ? results[0].subtract(BigInteger.ONE) : results[0]; } else { result = value.divide(otherValue); } return bignorm(runtime, result); }
/** * Return a Bignum or Fixnum (Integer) for the given value, or raise FloatDomainError if it is out of range. * * MRI: rb_dbl2big */ public static RubyInteger newBignorm(Ruby runtime, double value) { try { return bignorm(runtime, toBigInteger(value)); } catch (NumberFormatException nfe) { throw runtime.newFloatDomainError(Double.toString(value)); } }
/** * Return a Bignum or Fixnum (Integer) for the given value, or raise FloatDomainError if it is out of range. * * MRI: rb_dbl2big */ public static RubyInteger newBignorm(Ruby runtime, double value) { try { return bignorm(runtime, toBigInteger(value)); } catch (NumberFormatException nfe) { throw runtime.newFloatDomainError(Double.toString(value)); } }
@Override public IRubyObject op_mod(ThreadContext context, long other) { if (other == 0) throw context.runtime.newZeroDivisionError(); BigInteger result = value.mod(long2big(other < 0 ? -other : other)); if (other < 0 && result.signum() != 0) result = long2big(other).add(result); return bignorm(context.runtime, result); }
@Override public IRubyObject op_mod(ThreadContext context, long other) { if (other == 0) throw context.runtime.newZeroDivisionError(); BigInteger result = value.mod(long2big(other < 0 ? -other : other)); if (other < 0 && result.signum() != 0) result = long2big(other).add(result); return bignorm(context.runtime, result); }
private IRubyObject addFixnum(long other) { BigInteger result = value.add(BigInteger.valueOf(other)); if (other > 0 && value.signum() > 0) return new RubyBignum(getRuntime(), result); return bignorm(getRuntime(), result); }
private IRubyObject addFixnum(long other) { BigInteger result = value.add(BigInteger.valueOf(other)); if (other > 0 && value.signum() > 0) return new RubyBignum(getRuntime(), result); return bignorm(getRuntime(), result); }
final RubyInteger to_int(Ruby runtime) { checkFloatDomain(); try { return RubyFixnum.newFixnum(runtime, value.longValueExact()); } catch (ArithmeticException ex) { return RubyBignum.bignorm(runtime, value.toBigInteger()); } }
/** rb_big_and * */ @Override public IRubyObject op_and(ThreadContext context, IRubyObject other) { if (other instanceof RubyBignum) { return bignorm(context.runtime, value.and(((RubyBignum) other).value)); } if (other instanceof RubyFixnum) { return op_and(context, (RubyFixnum) other); } return coerceBit(context, sites(context).checked_op_and, other); }
@Override public IRubyObject sqrt(ThreadContext context) { Ruby runtime = context.runtime; if (isNegative()) { throw runtime.newMathDomainError("Numerical argument is out of domain - isqrt"); } return bignorm(runtime, floorSqrt(value)); }
@Override public IRubyObject sqrt(ThreadContext context) { Ruby runtime = context.runtime; if (isNegative()) { throw runtime.newMathDomainError("Numerical argument is out of domain - isqrt"); } return bignorm(runtime, floorSqrt(value)); }
@JRubyMethod(name = {"to_i", "to_int"}, compat = CompatVersion.RUBY1_8) public IRubyObject to_int() { if (isNaN() || infinitySign != 0) { return getRuntime().getNil(); } try { return RubyNumeric.int2fix(getRuntime(), value.longValueExact()); } catch (ArithmeticException ae) { return RubyBignum.bignorm(getRuntime(), value.toBigInteger()); } }