public static RubyInteger f_sub(ThreadContext context, RubyInteger x, RubyInteger y) { return (RubyInteger) x.op_minus(context, y); }
public static RubyInteger f_sub(ThreadContext context, RubyInteger x, RubyInteger y) { return (RubyInteger) x.op_minus(context, y); }
public IRubyObject op_minus(ThreadContext context, long other) { return op_minus(context, RubyFixnum.newFixnum(context.runtime, other)); }
public IRubyObject op_minus(ThreadContext context, long other) { return op_minus(context, RubyFixnum.newFixnum(context.runtime, other)); }
private RubyInteger roundHalfDown(ThreadContext context) { RubyInteger num = this.num, den = this.den; final boolean neg = num.isNegative(); if (neg) { num = (RubyInteger) num.op_uminus(context); } num = (RubyInteger) ((RubyInteger) num.op_mul(context, 2)).op_plus(context, den); num = (RubyInteger) num.op_minus(context, 1); den = (RubyInteger) den.op_mul(context, 2); num = (RubyInteger) num.idiv(context, den); if (neg) { num = (RubyInteger) num.op_uminus(context); } return num; }
private RubyInteger roundHalfDown(ThreadContext context) { RubyInteger num = this.num, den = this.den; final boolean neg = num.isNegative(); if (neg) { num = (RubyInteger) num.op_uminus(context); } num = (RubyInteger) ((RubyInteger) num.op_mul(context, 2)).op_plus(context, den); num = (RubyInteger) num.op_minus(context, 1); den = (RubyInteger) den.op_mul(context, 2); num = (RubyInteger) num.idiv(context, den); if (neg) { num = (RubyInteger) num.op_uminus(context); } return num; }
public RubyNumeric roundShared(ThreadContext context, int ndigits, RoundingMode roundingMode) { Ruby runtime = context.runtime; RubyNumeric f, h, n, r; if (int_round_zero_p(context, ndigits)) { return RubyFixnum.zero(runtime); } f = (RubyNumeric) int_pow(context, 10, -ndigits); if (this instanceof RubyFixnum && f instanceof RubyFixnum) { long x = fix2long(this), y = fix2long(f); boolean neg = x < 0; if (neg) x = -x; x = doRound(context, roundingMode, x, y); if (neg) x = -x; return RubyFixnum.newFixnum(runtime, x); } if (f instanceof RubyFloat) { /* then int_pow overflow */ return RubyFixnum.zero(runtime); } h = (RubyNumeric) f.idiv(context, 2); r = (RubyNumeric) this.op_mod(context, f); n = (RubyNumeric) this.op_minus(context, r); r = (RubyNumeric) r.op_cmp(context, h); if (r.isPositive(context).isTrue() || (r.isZero() && doRoundCheck(context, roundingMode, this, n, f))) { n = (RubyNumeric) n.op_plus(context, f); } return n; }
public RubyNumeric roundShared(ThreadContext context, int ndigits, RoundingMode roundingMode) { Ruby runtime = context.runtime; RubyNumeric f, h, n, r; if (int_round_zero_p(context, ndigits)) { return RubyFixnum.zero(runtime); } f = (RubyNumeric) int_pow(context, 10, -ndigits); if (this instanceof RubyFixnum && f instanceof RubyFixnum) { long x = fix2long(this), y = fix2long(f); boolean neg = x < 0; if (neg) x = -x; x = doRound(context, roundingMode, x, y); if (neg) x = -x; return RubyFixnum.newFixnum(runtime, x); } if (f instanceof RubyFloat) { /* then int_pow overflow */ return RubyFixnum.zero(runtime); } h = (RubyNumeric) f.idiv(context, 2); r = (RubyNumeric) this.op_mod(context, f); n = (RubyNumeric) this.op_minus(context, r); r = (RubyNumeric) r.op_cmp(context, h); if (r.isPositive(context).isTrue() || (r.isZero() && doRoundCheck(context, roundingMode, this, n, f))) { n = (RubyNumeric) n.op_plus(context, f); } return n; }
den = (RubyInteger) one.op_lshift(context, RubyFixnum.one(runtime).op_minus(context, n)); a = RubyRational.newRationalRaw(runtime, two_times_f.op_minus(context, 1), den); b = RubyRational.newRationalRaw(runtime, two_times_f.op_plus(context, 1), den);
den = (RubyInteger) one.op_lshift(context, RubyFixnum.one(runtime).op_minus(context, n)); a = RubyRational.newRationalRaw(runtime, two_times_f.op_minus(context, 1), den); b = RubyRational.newRationalRaw(runtime, two_times_f.op_plus(context, 1), den);