@JRubyMethod(name = "gets", writes = FrameField.LASTLINE, compat = RUBY1_9) public IRubyObject gets19(ThreadContext context, IRubyObject arg) { Ruby runtime = context.runtime; ByteList separator; long limit = -1; IRubyObject test = TypeConverter.checkIntegerType(runtime, arg, "to_int"); if (test instanceof RubyInteger) { limit = RubyInteger.fix2long(test); separator = separator(runtime); } else { separator = separator(runtime, arg); } IRubyObject result = getline(context, separator, limit); if (!result.isNil()) context.setLastLine(result); return result; }
@JRubyMethod(name = "gets", writes = FrameField.LASTLINE, compat = RUBY1_9) public IRubyObject gets19(ThreadContext context, IRubyObject arg) { Ruby runtime = context.runtime; ByteList separator; long limit = -1; IRubyObject test = TypeConverter.checkIntegerType(runtime, arg, "to_int"); if (test instanceof RubyInteger) { limit = RubyInteger.fix2long(test); separator = separator(runtime); } else { separator = separator(runtime, arg); } IRubyObject result = getline(context, separator, limit); if (!result.isNil()) context.setLastLine(result); return result; }
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; }