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); }
private IRubyObject addBignum(BigInteger other) { BigInteger result = value.add(other); if (value.signum() > 0 && other.signum() > 0) return new RubyBignum(getRuntime(), result); return bignorm(getRuntime(), result); }
private IRubyObject checkShiftDown(RubyBignum other) { if (other.value.signum() == 0) return RubyFixnum.zero(getRuntime()); if (value.compareTo(LONG_MIN) < 0 || value.compareTo(LONG_MAX) > 0) { return other.value.signum() >= 0 ? RubyFixnum.zero(getRuntime()) : RubyFixnum.minus_one(getRuntime()); } return getRuntime().getNil(); }
/** rb_big_eql * */ @JRubyMethod(name = {"eql?", "==="}, required = 1, compat = RUBY1_8) @Override public IRubyObject eql_p(IRubyObject other) { if (other instanceof RubyBignum) { return value.compareTo(((RubyBignum)other).value) == 0 ? getRuntime().getTrue() : getRuntime().getFalse(); } return getRuntime().getFalse(); }
/** rb_big2long * */ public static long big2long(RubyBignum value) { BigInteger big = value.getValue(); if (big.compareTo(LONG_MIN) < 0 || big.compareTo(LONG_MAX) > 0) { throw value.getRuntime().newRangeError("bignum too big to convert into `long'"); } return big.longValue(); }
/** rb_big2long * */ public static long big2long(RubyBignum value) { BigInteger big = value.getValue(); if (big.compareTo(LONG_MIN) < 0 || big.compareTo(LONG_MAX) > 0) { throw value.getRuntime().newRangeError("bignum too big to convert into `long'"); } return big.longValue(); }
/** rb_big_hash * */ @JRubyMethod(name = "hash") @Override public RubyFixnum hash() { return getRuntime().newFixnum(value.hashCode()); }
@Override public RubyString to_s() { return RubyString.newUSASCIIString(getRuntime(), getValue().toString(10)); }
@Override public RubyString to_s(IRubyObject arg0) { int base = num2int(arg0); if (base < 2 || base > 36) { throw getRuntime().newArgumentError("illegal radix " + base); } return RubyString.newUSASCIIString(getRuntime(), getValue().toString(base)); }
@JRubyMethod(name = "to_s") @Override public IRubyObject to_s() { int base = 10; return RubyString.newUSASCIIString(getRuntime(), getValue().toString(base)); }
@Override public final int compareTo(IRubyObject other) { if (other instanceof RubyBignum) { return value.compareTo(((RubyBignum)other).value); } return (int)coerceCmp(getRuntime().getCurrentContext(), "<=>", other).convertToInteger().getLongValue(); }
/** rb_big_to_f * */ @JRubyMethod(name = "to_f") public IRubyObject to_f() { return RubyFloat.newFloat(getRuntime(), getDoubleValue()); }
@Override public final int compareTo(IRubyObject other) { if (other instanceof RubyBignum) { return value.compareTo(((RubyBignum)other).value); } ThreadContext context = getRuntime().getCurrentContext(); return (int)coerceCmp(context, sites(context).op_cmp, other).convertToInteger().getLongValue(); }
@Override public final int compareTo(IRubyObject other) { if (other instanceof RubyBignum) { return value.compareTo(((RubyBignum)other).value); } ThreadContext context = getRuntime().getCurrentContext(); return (int)coerceCmp(context, sites(context).op_cmp, other).convertToInteger().getLongValue(); }
/** rb_big2dbl * */ public static double big2dbl(RubyBignum value) { BigInteger big = value.getValue(); double dbl = convertToDouble(big); if (dbl == Double.NEGATIVE_INFINITY || dbl == Double.POSITIVE_INFINITY) { value.getRuntime().getWarnings().warn(ID.BIGNUM_FROM_FLOAT_RANGE, "Bignum out of Float range"); } return dbl; }
public IRubyObject opMulOther(ThreadContext context, IRubyObject other) { if (other instanceof RubyFloat) { return RubyFloat.newFloat(getRuntime(), big2dbl(this) * ((RubyFloat) other).getDoubleValue()); } return coerceBin(context, "*", other); }
public IRubyObject opMulOther(ThreadContext context, IRubyObject other) { if (other instanceof RubyFloat) { return RubyFloat.newFloat(getRuntime(), big2dbl(this) * ((RubyFloat) other).getDoubleValue()); } return coerceBin(context, "*", other); }
/** rb_big2dbl * */ public static double big2dbl(RubyBignum value) { BigInteger big = value.getValue(); double dbl = convertToDouble(big); if (dbl == Double.NEGATIVE_INFINITY || dbl == Double.POSITIVE_INFINITY) { value.getRuntime().getWarnings().warn(ID.BIGNUM_FROM_FLOAT_RANGE, "Bignum out of Float range"); } return dbl; }
/** rb_big_quo * */ @JRubyMethod(name = "quo", required = 1, compat = RUBY1_8) @Override public IRubyObject quo(ThreadContext context, IRubyObject other) { if (other instanceof RubyNumeric) { return RubyFloat.newFloat(getRuntime(), big2dbl(this) / ((RubyNumeric) other).getDoubleValue()); } else { return coerceBin(context, "quo", other); } }