public static Random randomFromBignum(RubyBignum seed) { BigInteger big = seed.getBigIntegerValue(); return randomFromBigInteger(big); }
public static Random randomFromBignum(RubyBignum seed) { BigInteger big = seed.getBigIntegerValue(); return randomFromBigInteger(big); }
private static RubyBigDecimal newInstance(Ruby runtime, IRubyObject recv, RubyBignum arg, MathContext mathContext) { final BigInteger value = arg.getBigIntegerValue(); if (value.equals(BigInteger.ZERO)) return newZero(runtime, 1); return new RubyBigDecimal(runtime, (RubyClass) recv, new BigDecimal(value, mathContext)); }
private static RubyBigDecimal newInstance(Ruby runtime, IRubyObject recv, RubyBignum arg, MathContext mathContext) { final BigInteger value = arg.getBigIntegerValue(); if (value.equals(BigInteger.ZERO)) return newZero(runtime, 1); return new RubyBigDecimal(runtime, (RubyClass) recv, new BigDecimal(value, mathContext)); }
private static boolean isEven(final RubyNumeric x) { if (x instanceof RubyFixnum) return (((RubyFixnum) x).getLongValue() & 1) == 0; if (x instanceof RubyBignum) { return ((RubyBignum) x).getBigIntegerValue().testBit(0) == false; // 0-th bit -> 0 } return false; }
private static boolean isEven(final RubyNumeric x) { if (x instanceof RubyFixnum) return (((RubyFixnum) x).getLongValue() & 1) == 0; if (x instanceof RubyBignum) { return ((RubyBignum) x).getBigIntegerValue().testBit(0) == false; // 0-th bit -> 0 } return false; }
RandomType(IRubyObject vseed, RubyBignum state, int left) { this.seed = vseed.convertToInteger(); byte[] bytes = state.getBigIntegerValue().toByteArray(); int[] ints = new int[bytes.length / 4]; for (int i = 0; i < ints.length; ++i) { ints[i] = getIntBigIntegerBuffer(bytes, i); } this.mt = new Random(ints, left); }
RandomType(IRubyObject vseed, RubyBignum state, int left) { this.seed = vseed.convertToInteger(); byte[] bytes = state.getBigIntegerValue().toByteArray(); int[] ints = new int[bytes.length / 4]; for (int i = 0; i < ints.length; ++i) { ints[i] = getIntBigIntegerBuffer(bytes, i); } this.impl = new Random(ints, left); }
RandomType(IRubyObject vseed, RubyBignum state, int left) { this.seed = vseed.convertToInteger(); byte[] bytes = state.getBigIntegerValue().toByteArray(); int[] ints = new int[bytes.length / 4]; for (int i = 0; i < ints.length; ++i) { ints[i] = getIntBigIntegerBuffer(bytes, i); } this.impl = new Random(ints, left); }
RandomType(IRubyObject vseed, RubyBignum state, int left) { this.seed = vseed.convertToInteger(); byte[] bytes = state.getBigIntegerValue().toByteArray(); int[] ints = new int[bytes.length / 4]; for (int i = 0; i < ints.length; ++i) { ints[i] = getIntBigIntegerBuffer(bytes, i); } this.mt = new Random(ints, left); }
protected IRubyObject intPowTmp3(ThreadContext context, RubyInteger y, RubyBignum m, boolean negaFlg) { Ruby runtime = context.runtime; BigInteger xn, yn, mn, zn; if (this instanceof RubyFixnum) { xn = BigInteger.valueOf(this.getLongValue()); } else { xn = this.getBigIntegerValue(); } if (y instanceof RubyFixnum) { yn = BigInteger.valueOf(y.getLongValue()); } else { yn = y.getBigIntegerValue(); } mn = m.getBigIntegerValue(); zn = xn.modPow(yn, mn); if (negaFlg & zn.signum() == 1) { zn = zn.negate(); } return RubyBignum.bignorm(runtime, zn); }
protected IRubyObject intPowTmp3(ThreadContext context, RubyInteger y, RubyBignum m, boolean negaFlg) { Ruby runtime = context.runtime; BigInteger xn, yn, mn, zn; if (this instanceof RubyFixnum) { xn = BigInteger.valueOf(this.getLongValue()); } else { xn = this.getBigIntegerValue(); } if (y instanceof RubyFixnum) { yn = BigInteger.valueOf(y.getLongValue()); } else { yn = y.getBigIntegerValue(); } mn = m.getBigIntegerValue(); zn = xn.modPow(yn, mn); if (negaFlg & zn.signum() == 1) { zn = zn.negate(); } return RubyBignum.bignorm(runtime, zn); }
private static IRubyObject randLimitedBignum(ThreadContext context, RandomType random, RubyBignum limit) { byte[] buf = limit.getBigIntegerValue().toByteArray(); byte[] bytes = new byte[buf.length]; int len = (buf.length + 3) / 4;
private static IRubyObject randLimitedBignum(ThreadContext context, RandomType random, RubyBignum limit) { byte[] buf = limit.getBigIntegerValue().toByteArray(); byte[] bytes = new byte[buf.length]; int len = (buf.length + 3) / 4;
BigInteger big = ((RubyBignum) seed).getBigIntegerValue(); if (big.signum() < 0) { big = big.abs();
BigInteger big = ((RubyBignum) seed).getBigIntegerValue(); if (big.signum() < 0) { big = big.abs();
@JRubyMethod(name = {"concat", "<<"}, compat = RUBY1_9) public RubyString concat19(ThreadContext context, IRubyObject other) { Ruby runtime = context.runtime; if (other instanceof RubyFixnum) { int c = RubyNumeric.num2int(other); if (c < 0) { throw runtime.newRangeError("negative string size (or size too big)"); } return concatNumeric(runtime, c); } else if (other instanceof RubyBignum) { if (((RubyBignum) other).getBigIntegerValue().signum() < 0) { throw runtime.newRangeError("negative string size (or size too big)"); } long c = ((RubyBignum) other).getLongValue(); return concatNumeric(runtime, (int) c); } if (other instanceof RubySymbol) throw runtime.newTypeError("can't convert Symbol into String"); return append19(other); }
/** rb_str_concat * */ @JRubyMethod(name = "<<") public RubyString concatSingle(ThreadContext context, IRubyObject other) { Ruby runtime = context.runtime; if (other instanceof RubyFixnum) { long c = RubyNumeric.num2long(other); if (c < 0) { throw runtime.newRangeError(c + " out of char range"); } return concatNumeric(runtime, (int)(c & 0xFFFFFFFF)); } else if (other instanceof RubyBignum) { if (((RubyBignum) other).getBigIntegerValue().signum() < 0) { throw runtime.newRangeError("negative string size (or size too big)"); } long c = ((RubyBignum) other).getLongValue(); return concatNumeric(runtime, (int) c); } if (other instanceof RubySymbol) throw runtime.newTypeError("can't convert Symbol into String"); return append19(other); }
@JRubyMethod(name = {"concat", "<<"}, compat = RUBY1_9) public RubyString concat19(ThreadContext context, IRubyObject other) { Ruby runtime = context.runtime; if (other instanceof RubyFixnum) { int c = RubyNumeric.num2int(other); if (c < 0) { throw runtime.newRangeError("negative string size (or size too big)"); } return concatNumeric(runtime, c); } else if (other instanceof RubyBignum) { if (((RubyBignum) other).getBigIntegerValue().signum() < 0) { throw runtime.newRangeError("negative string size (or size too big)"); } long c = ((RubyBignum) other).getLongValue(); return concatNumeric(runtime, (int) c); } if (other instanceof RubySymbol) throw runtime.newTypeError("can't convert Symbol into String"); return append19(other); }
/** rb_str_concat * */ @JRubyMethod(name = "<<") public RubyString concatSingle(ThreadContext context, IRubyObject other) { Ruby runtime = context.runtime; if (other instanceof RubyFixnum) { long c = RubyNumeric.num2long(other); if (c < 0) { throw runtime.newRangeError(c + " out of char range"); } return concatNumeric(runtime, (int)(c & 0xFFFFFFFF)); } else if (other instanceof RubyBignum) { if (((RubyBignum) other).getBigIntegerValue().signum() < 0) { throw runtime.newRangeError("negative string size (or size too big)"); } long c = ((RubyBignum) other).getLongValue(); return concatNumeric(runtime, (int) c); } if (other instanceof RubySymbol) throw runtime.newTypeError("can't convert Symbol into String"); return append19(other); }