public static long other2u64(IRubyObject parameter) { if (parameter instanceof RubyBignum) { return ((RubyBignum) parameter).getValue().longValue(); } else { return other2long(parameter); } }
/** rb_big2ulong * This is here because for C extensions ulong can hold different values without throwing a RangeError */ public static long big2ulong(RubyBignum value) { BigInteger big = value.getValue(); if (big.compareTo(LONG_MIN) <= 0 || big.compareTo(ULONG_MAX) > 0) { throw value.getRuntime().newRangeError("bignum too big to convert into `ulong'"); } return value.getValue().longValue(); }
/** rb_big2ulong * This is here because for C extensions ulong can hold different values without throwing a RangeError */ public static long big2ulong(RubyBignum value) { BigInteger big = value.getValue(); if (big.compareTo(LONG_MIN) <= 0 || big.compareTo(ULONG_MAX) > 0) { throw value.getRuntime().newRangeError("bignum too big to convert into `ulong'"); } return value.getValue().longValue(); }
public static long other2u64(IRubyObject parameter) { if (parameter instanceof RubyBignum) { return ((RubyBignum) parameter).getValue().longValue(); } else { return other2long(parameter); } }
public static final long uint64Value(IRubyObject parameter) { final long value = parameter instanceof RubyBignum ? ((RubyBignum) parameter).getValue().longValue() :longValue(parameter); return value; }
/** 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(); }
private static long num2quad(IRubyObject arg) { if (arg.isNil()) return 0L; if (arg instanceof RubyBignum) { BigInteger big = ((RubyBignum) arg).getValue(); return big.longValue(); } return RubyNumeric.num2long(arg); }
@JRubyMethod(name = "to_s") @Override public IRubyObject to_s() { int base = 10; return RubyString.newUSASCIIString(getRuntime(), getValue().toString(base)); }
private IRubyObject op_gtOther(ThreadContext context, IRubyObject other) { if (other instanceof RubyBignum) { return RubyBoolean.newBoolean(context.runtime, BigInteger.valueOf(value).compareTo(((RubyBignum) other).getValue()) > 0); } if (other instanceof RubyFloat) { return RubyBoolean.newBoolean(context.runtime, (double) value > ((RubyFloat) other).getDoubleValue()); } return coerceRelOp(context, ">", other); }
private IRubyObject op_gtOther(ThreadContext context, IRubyObject other) { if (other instanceof RubyBignum) { return RubyBoolean.newBoolean(context.runtime, BigInteger.valueOf(value).compareTo(((RubyBignum) other).getValue()) > 0); } if (other instanceof RubyFloat) { return RubyBoolean.newBoolean(context.runtime, (double) value > ((RubyFloat) other).getDoubleValue()); } return coerceRelOp(context, ">", other); }
private IRubyObject op_leOther(ThreadContext context, IRubyObject other) { if (other instanceof RubyBignum) { return RubyBoolean.newBoolean(context.runtime, BigInteger.valueOf(value).compareTo(((RubyBignum) other).getValue()) <= 0); } if (other instanceof RubyFloat) { return RubyBoolean.newBoolean(context.runtime, (double) value <= ((RubyFloat) other).getDoubleValue()); } return coerceRelOp(context, "<=", other); }
private IRubyObject compareOther(ThreadContext context, IRubyObject other) { if (other instanceof RubyBignum) { return newFixnum(context.runtime, BigInteger.valueOf(value).compareTo(((RubyBignum)other).getValue())); } if (other instanceof RubyFloat) { return dbl_cmp(context.runtime, (double)value, ((RubyFloat)other).getDoubleValue()); } return coerceCmp(context, "<=>", other); }
private IRubyObject op_leOther(ThreadContext context, IRubyObject other) { if (other instanceof RubyBignum) { return RubyBoolean.newBoolean(context.runtime, BigInteger.valueOf(value).compareTo(((RubyBignum) other).getValue()) <= 0); } if (other instanceof RubyFloat) { return RubyBoolean.newBoolean(context.runtime, (double) value <= ((RubyFloat) other).getDoubleValue()); } return coerceRelOp(context, "<=", other); }
private IRubyObject compareOther(ThreadContext context, IRubyObject other) { if (other instanceof RubyBignum) { return newFixnum(context.runtime, BigInteger.valueOf(value).compareTo(((RubyBignum)other).getValue())); } if (other instanceof RubyFloat) { return dbl_cmp(context.runtime, (double)value, ((RubyFloat)other).getDoubleValue()); } return coerceCmp(context, "<=>", other); }
private IRubyObject op_geOther(ThreadContext context, IRubyObject other) { if (other instanceof RubyBignum) { return RubyBoolean.newBoolean(context.runtime, BigInteger.valueOf(value).compareTo(((RubyBignum) other).getValue()) >= 0); } if (other instanceof RubyFloat) { return RubyBoolean.newBoolean(context.runtime, (double) value >= ((RubyFloat) other).getDoubleValue()); } return coerceRelOp(context, ">=", other); }
private IRubyObject op_equalOther(ThreadContext context, IRubyObject other) { if (other instanceof RubyBignum) { return RubyBoolean.newBoolean(context.runtime, BigInteger.valueOf(value).compareTo(((RubyBignum) other).getValue()) == 0); } if (other instanceof RubyFloat) { return RubyBoolean.newBoolean(context.runtime, (double) value == ((RubyFloat) other).getDoubleValue()); } return super.op_num_equal(context, other); }
private IRubyObject op_ltOther(ThreadContext context, IRubyObject other) { if (other instanceof RubyBignum) { return RubyBoolean.newBoolean(context.runtime, BigInteger.valueOf(value).compareTo(((RubyBignum) other).getValue()) < 0); } if (other instanceof RubyFloat) { return RubyBoolean.newBoolean(context.runtime, (double) value < ((RubyFloat) other).getDoubleValue()); } return coerceRelOp(context, "<", other); }
private int compareToOther(IRubyObject other) { if (other instanceof RubyBignum) return BigInteger.valueOf(value).compareTo(((RubyBignum)other).getValue()); if (other instanceof RubyFloat) return Double.compare((double)value, ((RubyFloat)other).getDoubleValue()); return (int)coerceCmp(getRuntime().getCurrentContext(), "<=>", 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; }
/** rb_cmpint * */ public static int cmpint(ThreadContext context, IRubyObject val, IRubyObject a, IRubyObject b) { if (val.isNil()) cmperr(a, b); if (val instanceof RubyFixnum) return RubyNumeric.fix2int((RubyFixnum) val); if (val instanceof RubyBignum) return ((RubyBignum) val).getValue().signum() == -1 ? -1 : 1; RubyFixnum zero = RubyFixnum.zero(context.runtime); if (val.callMethod(context, ">", zero).isTrue()) return 1; if (val.callMethod(context, "<", zero).isTrue()) return -1; return 0; }