public static int num2uint(IRubyObject value) { long longVal = RubyNumeric.num2long(value); if (longVal > UINT_MAX) throw value.getRuntime().newRangeError("Integer " + longVal + " too big to convert to 'unsigned int'"); long num = longVal; if (num > Integer.MAX_VALUE || num < Integer.MIN_VALUE) // encode to UINT32 num = (-longVal ^ (-1l >>> 32) ) + 1; RubyNumeric.checkInt(value, num); return (int) num; }
public static long num2ulong(Ruby runtime, IRubyObject value) { if (value instanceof RubyFloat) { RubyBignum bignum = RubyBignum.newBignum(runtime, ((RubyFloat) value).getDoubleValue()); return RubyBignum.big2ulong(bignum); } else if (value instanceof RubyBignum) { return RubyBignum.big2ulong((RubyBignum) value); } else { return RubyNumeric.num2long(value); } }
break; case INT64: RubyNumeric.num2long(value); break; case UINT32:
break; case INT64: val = RubyNumeric.num2long(value); break; case UINT32:
/** * Converts characters like 'a' or 't' to an integer value * * @param parameter * @return */ public static final long longValue(IRubyObject parameter) { return RubyNumeric.num2long(parameter); }
public void encode(Ruby runtime, IRubyObject o, ByteList result){ int s = o == runtime.getNil() ? 0 : (int)RubyNumeric.num2long(o); encodeIntLittleEndian(result, s); } };
private static BigDecimal toBigDecimal(final RubyInteger value) { if (value instanceof RubyFixnum) { return BigDecimal.valueOf(RubyNumeric.num2long(value)); } return new BigDecimal(value.getBigIntegerValue()); }
/** rb_num2int, NUM2INT * */ public static int num2int(IRubyObject arg) { long num = num2long(arg); checkInt(arg, num); return (int)num; }
@JRubyMethod(name = "crc32_combine", required = 3, module = true, visibility = PRIVATE) public static IRubyObject crc32_combine(IRubyObject recv, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2) { long crc1 = RubyNumeric.num2long(arg0); long crc2 = RubyNumeric.num2long(arg1); long len2 = RubyNumeric.num2long(arg2); long crc3 = com.jcraft.jzlib.JZlib.crc32_combine(crc1, crc2, len2); return recv.getRuntime().newFixnum(crc3); }
@JRubyMethod(name = "adler32_combine", required = 3, module = true, visibility = PRIVATE) public static IRubyObject adler32_combine(IRubyObject recv, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2) { long adler1 = RubyNumeric.num2long(arg0); long adler2 = RubyNumeric.num2long(arg1); long len2 = RubyNumeric.num2long(arg2); long adler3 = com.jcraft.jzlib.JZlib.adler32_combine(adler1, adler2, len2); return recv.getRuntime().newFixnum(adler3); }
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); }
/** rb_ary_at * */ @JRubyMethod(name = "at", required = 1) public IRubyObject at(IRubyObject pos) { return entry(RubyNumeric.num2long(pos)); }
public static int fix2int(IRubyObject arg) { long num = arg instanceof RubyFixnum ? fix2long(arg) : num2long(arg); checkInt(arg, num); return (int) num; }
/** rb_ary_insert * */ @JRubyMethod(name = "insert") public IRubyObject insert(IRubyObject arg) { modifyCheck(); RubyNumeric.num2long(arg); return this; }
/** rb_ary_take * */ @JRubyMethod(name = "take") public IRubyObject take(ThreadContext context, IRubyObject n) { Ruby runtime = context.runtime; long len = RubyNumeric.num2long(n); if (len < 0) throw runtime.newArgumentError("attempt to take negative size"); return subseq(0, len); }
@JRubyMethod public RubyFixnum hash(ThreadContext context) { Ruby runtime = context.runtime; int h = getType().hashCode(); IRubyObject[] values = this.values; for (int i = 0; i < values.length; i++) { h = (h << 1) | (h < 0 ? 1 : 0); IRubyObject hash = context.safeRecurse(HashRecursive.INSTANCE, runtime, values[i], "hash", true); h ^= RubyNumeric.num2long(hash); } return runtime.newFixnum(h); }
/** rb_ary_take * */ @JRubyMethod(name = "drop") public IRubyObject drop(ThreadContext context, IRubyObject n) { Ruby runtime = context.runtime; long pos = RubyNumeric.num2long(n); if (pos < 0) throw runtime.newArgumentError("attempt to drop negative size"); IRubyObject result = subseq(pos, realLength); return result.isNil() ? runtime.newEmptyArray() : result; }
@JRubyMethod(name = "each_slice") public IRubyObject each_slice(ThreadContext context, IRubyObject arg, final Block block) { int size = (int) RubyNumeric.num2long(arg); if (size <= 0) throw context.runtime.newArgumentError("invalid size"); return block.isGiven() ? RubyEnumerable.each_sliceCommon(context, this, size, block) : enumeratorize(context.runtime, getType(), this, "each_slice", arg); }
@JRubyMethod(name = "each_slice") public static IRubyObject each_slice(ThreadContext context, IRubyObject self, IRubyObject arg, final Block block) { int size = (int) RubyNumeric.num2long(arg); if (size <= 0) throw context.runtime.newArgumentError("invalid size"); return block.isGiven() ? each_sliceCommon(context, self, size, block) : enumeratorizeWithSize(context, self, "each_slice", new IRubyObject[]{arg}, eachSliceSizeFn(context, self)); }
/** rb_ary_cycle * */ @JRubyMethod(name = "cycle") public IRubyObject cycle(ThreadContext context, IRubyObject arg, Block block) { if (arg.isNil()) return cycle(context, block); if (!block.isGiven()) return enumeratorizeWithSize(context, this, "cycle", new IRubyObject[] {arg}, cycleSizeFn(context)); long times = RubyNumeric.num2long(arg); if (times <= 0) return context.nil; return cycleCommon(context, times, block); }