return RubyFloat.newFloat(runtime, div); } else { return RubyNumeric.dbl2num(runtime, div);
return RubyFloat.newFloat(runtime, div); } else { return RubyNumeric.dbl2num(runtime, div);
@JRubyMethod(name = "to_r", compat = CompatVersion.RUBY1_9) public IRubyObject to_r(ThreadContext context) { long[]exp = new long[1]; double f = frexp(value, exp); f = ldexp(f, DBL_MANT_DIG); long n = exp[0] - DBL_MANT_DIG; Ruby runtime = context.runtime; IRubyObject rf = RubyNumeric.dbl2num(runtime, f); IRubyObject rn = RubyFixnum.newFixnum(runtime, n); return f_mul(context, rf, f_expt(context, RubyFixnum.newFixnum(runtime, FLT_RADIX), rn)); }
@JRubyMethod(name = "to_r", compat = CompatVersion.RUBY1_9) public IRubyObject to_r(ThreadContext context) { long[]exp = new long[1]; double f = frexp(value, exp); f = ldexp(f, DBL_MANT_DIG); long n = exp[0] - DBL_MANT_DIG; Ruby runtime = context.runtime; IRubyObject rf = RubyNumeric.dbl2num(runtime, f); IRubyObject rn = RubyFixnum.newFixnum(runtime, n); return f_mul(context, rf, f_expt(context, RubyFixnum.newFixnum(runtime, FLT_RADIX), rn)); }
@JRubyMethod(name = "Integer", required = 1, module = true, visibility = PRIVATE, compat = RUBY1_8) public static IRubyObject new_integer(ThreadContext context, IRubyObject recv, IRubyObject object) { if (object instanceof RubyFloat) { double val = ((RubyFloat)object).getDoubleValue(); if (val >= (double) RubyFixnum.MAX || val < (double) RubyFixnum.MIN) { return RubyNumeric.dbl2num(context.runtime,((RubyFloat)object).getDoubleValue()); } } else if (object instanceof RubyFixnum || object instanceof RubyBignum) { return object; } else if (object instanceof RubyString) { return RubyNumeric.str2inum(context.runtime,(RubyString)object,0,true); } IRubyObject tmp = TypeConverter.convertToType(object, context.runtime.getInteger(), "to_int", false); if (tmp.isNil()) return object.convertToInteger("to_i"); return tmp; }
@JRubyMethod(name = "Integer", required = 1, module = true, visibility = PRIVATE, compat = RUBY1_8) public static IRubyObject new_integer(ThreadContext context, IRubyObject recv, IRubyObject object) { if (object instanceof RubyFloat) { double val = ((RubyFloat)object).getDoubleValue(); if (val >= (double) RubyFixnum.MAX || val < (double) RubyFixnum.MIN) { return RubyNumeric.dbl2num(context.runtime,((RubyFloat)object).getDoubleValue()); } } else if (object instanceof RubyFixnum || object instanceof RubyBignum) { return object; } else if (object instanceof RubyString) { return RubyNumeric.str2inum(context.runtime,(RubyString)object,0,true); } IRubyObject tmp = TypeConverter.convertToType(object, context.runtime.getInteger(), "to_int", false); if (tmp.isNil()) return object.convertToInteger("to_i"); return tmp; }
return RubyFloat.newFloat(runtime, pow); return RubyNumeric.dbl2num(runtime, pow);
private IRubyObject powerFixnum19(ThreadContext context, IRubyObject other) { Ruby runtime = context.runtime; long a = value; long b = ((RubyFixnum) other).value; if (b < 0) { return RubyRational.newRationalRaw(runtime, this).callMethod(context, "**", other); } if (b == 0) { return RubyFixnum.one(runtime); } if (b == 1) { return this; } if (a == 0) { return b > 0 ? RubyFixnum.zero(runtime) : RubyNumeric.dbl2num(runtime, 1.0 / 0.0); } if (a == 1) { return RubyFixnum.one(runtime); } if (a == -1) { return b % 2 == 0 ? RubyFixnum.one(runtime) : RubyFixnum.minus_one(runtime); } return Numeric.int_pow(context, a, b); }
return RubyFloat.newFloat(runtime, pow); return RubyNumeric.dbl2num(runtime, pow);
@JRubyMethod(name = "Integer", module = true, visibility = PRIVATE, compat = RUBY1_9) public static IRubyObject new_integer19(ThreadContext context, IRubyObject recv, IRubyObject object) { if (object instanceof RubyFloat) { double val = ((RubyFloat)object).getDoubleValue(); if (val > (double) RubyFixnum.MAX && val < (double) RubyFixnum.MIN) { return RubyNumeric.dbl2num(context.runtime,((RubyFloat)object).getDoubleValue()); } } else if (object instanceof RubyFixnum || object instanceof RubyBignum) { return object; } else if (object instanceof RubyString) { return RubyNumeric.str2inum(context.runtime,(RubyString)object,0,true); } else if(object instanceof RubyNil) { throw context.runtime.newTypeError("can't convert nil into Integer"); } IRubyObject tmp = TypeConverter.convertToType(object, context.runtime.getInteger(), "to_int", false); if (tmp.isNil()) return object.convertToInteger("to_i"); return tmp; }
@JRubyMethod(name = "Integer", module = true, visibility = PRIVATE, compat = RUBY1_9) public static IRubyObject new_integer19(ThreadContext context, IRubyObject recv, IRubyObject object) { if (object instanceof RubyFloat) { double val = ((RubyFloat)object).getDoubleValue(); if (val > (double) RubyFixnum.MAX && val < (double) RubyFixnum.MIN) { return RubyNumeric.dbl2num(context.runtime,((RubyFloat)object).getDoubleValue()); } } else if (object instanceof RubyFixnum || object instanceof RubyBignum) { return object; } else if (object instanceof RubyString) { return RubyNumeric.str2inum(context.runtime,(RubyString)object,0,true); } else if(object instanceof RubyNil) { throw context.runtime.newTypeError("can't convert nil into Integer"); } IRubyObject tmp = TypeConverter.convertToType(object, context.runtime.getInteger(), "to_int", false); if (tmp.isNil()) return object.convertToInteger("to_i"); return tmp; }
private IRubyObject powerFixnum19(ThreadContext context, IRubyObject other) { Ruby runtime = context.runtime; long a = value; long b = ((RubyFixnum) other).value; if (b < 0) { return RubyRational.newRationalRaw(runtime, this).callMethod(context, "**", other); } if (b == 0) { return RubyFixnum.one(runtime); } if (b == 1) { return this; } if (a == 0) { return b > 0 ? RubyFixnum.zero(runtime) : RubyNumeric.dbl2num(runtime, 1.0 / 0.0); } if (a == 1) { return RubyFixnum.one(runtime); } if (a == -1) { return b % 2 == 0 ? RubyFixnum.one(runtime) : RubyFixnum.minus_one(runtime); } return Numeric.int_pow(context, a, b); }
switch(type) { case ClassIndex.FLOAT: arg = RubyNumeric.dbl2num(arg.getRuntime(),((RubyFloat)arg).getValue()); break; case ClassIndex.STRING:
switch(type) { case ClassIndex.FLOAT: arg = RubyNumeric.dbl2num(arg.getRuntime(),((RubyFloat)arg).getValue()); break; case ClassIndex.STRING:
IRubyObject rf = RubyNumeric.dbl2num(runtime, f); IRubyObject rn = RubyFixnum.newFixnum(runtime, n);
IRubyObject rf = RubyNumeric.dbl2num(runtime, f); IRubyObject rn = RubyFixnum.newFixnum(runtime, n);