/** rb_big_to_f * */ @Override public IRubyObject to_f(ThreadContext context) { return RubyFloat.newFloat(context.runtime, getDoubleValue()); }
/** rb_big_to_f * */ @Override public IRubyObject to_f(ThreadContext context) { return RubyFloat.newFloat(context.runtime, getDoubleValue()); }
final RubyFloat fdivDouble(ThreadContext context, RubyBignum y) { double dx = getDoubleValue(); double dy = RubyBignum.big2dbl(y); if (Double.isInfinite(dx) || Double.isInfinite(dy)) { return (RubyFloat) fdivInt(context, y); } return context.runtime.newFloat(dx / dy); }
@Override public IRubyObject to_f() { return RubyFloat.newFloat(getRuntime(), getDoubleValue()); }
final RubyFloat fdivDouble(ThreadContext context, RubyBignum y) { double dx = getDoubleValue(); double dy = RubyBignum.big2dbl(y); if (Double.isInfinite(dx) || Double.isInfinite(dy)) { return (RubyFloat) fdivInt(context, y); } return context.runtime.newFloat(dx / dy); }
@Override public IRubyObject to_f() { return RubyFloat.newFloat(getRuntime(), getDoubleValue()); }
/** rb_big_to_f * */ @JRubyMethod(name = "to_f") public IRubyObject to_f() { return RubyFloat.newFloat(getRuntime(), getDoubleValue()); }
/** rb_big_to_f * */ @JRubyMethod(name = "to_f") public IRubyObject to_f() { return RubyFloat.newFloat(getRuntime(), getDoubleValue()); }
/** fix_quo * */ @JRubyMethod(name = "quo", compat = RUBY1_8) @Override public IRubyObject quo(ThreadContext context, IRubyObject other) { if (other instanceof RubyFixnum) { return RubyFloat.newFloat(context.runtime, (double) value / (double) ((RubyFixnum) other).value); } else if (other instanceof RubyBignum) { return RubyFloat.newFloat(context.runtime, (double) value / (double) ((RubyBignum) other).getDoubleValue()); } return coerceBin(context, "quo", other); }
/** fix_quo * */ @JRubyMethod(name = "quo", compat = RUBY1_8) @Override public IRubyObject quo(ThreadContext context, IRubyObject other) { if (other instanceof RubyFixnum) { return RubyFloat.newFloat(context.runtime, (double) value / (double) ((RubyFixnum) other).value); } else if (other instanceof RubyBignum) { return RubyFloat.newFloat(context.runtime, (double) value / (double) ((RubyBignum) other).getDoubleValue()); } return coerceBin(context, "quo", other); }
@Override public IRubyObject fdivDouble(ThreadContext context, IRubyObject y) { double dx, dy; dx = getDoubleValue(); if (y instanceof RubyFixnum) { long ly = ((RubyFixnum) y).getLongValue(); if (Double.isInfinite(dx)) { return fdivInt(context.runtime, BigDecimal.valueOf(ly)); } dy = (double) ly; } else if (y instanceof RubyBignum) { return fdivDouble(context, (RubyBignum) y); } else if (y instanceof RubyFloat) { dy = ((RubyFloat) y).getDoubleValue(); if (Double.isNaN(dy)) { return context.runtime.newFloat(dy); } if (Double.isInfinite(dx)) { return fdivFloat(context, (RubyFloat) y); } } else { return coerceBin(context, sites(context).fdiv, y); } return context.runtime.newFloat(dx / dy); }
@Override public IRubyObject fdivDouble(ThreadContext context, IRubyObject y) { double dx, dy; dx = getDoubleValue(); if (y instanceof RubyFixnum) { long ly = ((RubyFixnum) y).getLongValue(); if (Double.isInfinite(dx)) { return fdivInt(context.runtime, BigDecimal.valueOf(ly)); } dy = (double) ly; } else if (y instanceof RubyBignum) { return fdivDouble(context, (RubyBignum) y); } else if (y instanceof RubyFloat) { dy = ((RubyFloat) y).getDoubleValue(); if (Double.isNaN(dy)) { return context.runtime.newFloat(dy); } if (Double.isInfinite(dx)) { return fdivFloat(context, (RubyFloat) y); } } else { return coerceBin(context, sites(context).fdiv, y); } return context.runtime.newFloat(dx / dy); }
/** rb_big_pow * */ @JRubyMethod(name = {"**", "power"}, required = 1) public IRubyObject op_pow(ThreadContext context, IRubyObject other) { double d; if (other instanceof RubyFixnum) { RubyFixnum fix = (RubyFixnum) other; long fixValue = fix.getLongValue(); return op_pow(context, fixValue); } else if (other instanceof RubyBignum) { d = ((RubyBignum) other).getDoubleValue(); getRuntime().getWarnings().warn(ID.MAY_BE_TOO_BIG, "in a**b, b may be too big"); } else if (other instanceof RubyFloat) { d = ((RubyFloat) other).getDoubleValue(); } else { return coerceBin(context, "**", other); } return RubyFloat.newFloat(getRuntime(), Math.pow(big2dbl(this), d)); }
/** rb_big_pow * */ @JRubyMethod(name = {"**", "power"}, required = 1) public IRubyObject op_pow(ThreadContext context, IRubyObject other) { double d; if (other instanceof RubyFixnum) { RubyFixnum fix = (RubyFixnum) other; long fixValue = fix.getLongValue(); return op_pow(context, fixValue); } else if (other instanceof RubyBignum) { d = ((RubyBignum) other).getDoubleValue(); getRuntime().getWarnings().warn(ID.MAY_BE_TOO_BIG, "in a**b, b may be too big"); } else if (other instanceof RubyFloat) { d = ((RubyFloat) other).getDoubleValue(); } else { return coerceBin(context, "**", other); } return RubyFloat.newFloat(getRuntime(), Math.pow(big2dbl(this), d)); }
d = ((RubyBignum) other).getDoubleValue(); getRuntime().getWarnings().warn(ID.MAY_BE_TOO_BIG, "in a**b, b may be too big"); } else if (other instanceof RubyFloat) {
d = ((RubyBignum) other).getDoubleValue(); getRuntime().getWarnings().warn(ID.MAY_BE_TOO_BIG, "in a**b, b may be too big"); } else if (other instanceof RubyFloat) {
/** rb_big_pow * */ @Override @JRubyMethod(name = {"**", "power"}, required = 1) public IRubyObject op_pow(ThreadContext context, IRubyObject other) { Ruby runtime = context.runtime; if (other == RubyFixnum.zero(runtime)) return RubyFixnum.one(runtime); final double d; if (other instanceof RubyFloat) { d = ((RubyFloat) other).getDoubleValue(); if (compareTo(RubyFixnum.zero(runtime)) == -1 && d != Math.round(d)) { RubyComplex complex = RubyComplex.newComplexRaw(context.runtime, this); return sites(context).op_exp.call(context, complex, complex, other); } } else if (other instanceof RubyBignum) { d = ((RubyBignum) other).getDoubleValue(); context.runtime.getWarnings().warn(ID.MAY_BE_TOO_BIG, "in a**b, b may be too big"); } else if (other instanceof RubyFixnum) { return op_pow(context, other.convertToInteger().getLongValue()); } else { return coerceBin(context, sites(context).op_exp, other); } return pow(runtime, d); }
/** rb_big_pow * */ @Override @JRubyMethod(name = {"**", "power"}, required = 1) public IRubyObject op_pow(ThreadContext context, IRubyObject other) { Ruby runtime = context.runtime; if (other == RubyFixnum.zero(runtime)) return RubyFixnum.one(runtime); final double d; if (other instanceof RubyFloat) { d = ((RubyFloat) other).getDoubleValue(); if (compareTo(RubyFixnum.zero(runtime)) == -1 && d != Math.round(d)) { RubyComplex complex = RubyComplex.newComplexRaw(context.runtime, this); return sites(context).op_exp.call(context, complex, complex, other); } } else if (other instanceof RubyBignum) { d = ((RubyBignum) other).getDoubleValue(); context.runtime.getWarnings().warn(ID.MAY_BE_TOO_BIG, "in a**b, b may be too big"); } else if (other instanceof RubyFixnum) { return op_pow(context, other.convertToInteger().getLongValue()); } else { return coerceBin(context, sites(context).op_exp, other); } return pow(runtime, d); }
/** rb_num2dbl and NUM2DBL * */ public static double num2dbl(ThreadContext context, IRubyObject arg) { switch (((RubyBasicObject) arg).getNativeClassIndex()) { case FLOAT: return ((RubyFloat) arg).getDoubleValue(); case FIXNUM: if (context.sites.Fixnum.to_f.isBuiltin(getMetaClass(arg))) return ((RubyFixnum) arg).getDoubleValue(); break; case BIGNUM: if (context.sites.Bignum.to_f.isBuiltin(getMetaClass(arg))) return ((RubyBignum) arg).getDoubleValue(); break; case RATIONAL: if (context.sites.Rational.to_f.isBuiltin(getMetaClass(arg))) return ((RubyRational) arg).getDoubleValue(); break; case STRING: case NIL: case TRUE: case FALSE: throw context.runtime.newTypeError(str(context.runtime, "can't convert ", arg.inspect(), " into Float")); } IRubyObject val = TypeConverter.convertToType(arg, context.runtime.getFloat(), "to_f"); return ((RubyFloat) val).getDoubleValue(); }
/** rb_num2dbl and NUM2DBL * */ public static double num2dbl(ThreadContext context, IRubyObject arg) { switch (((RubyBasicObject) arg).getNativeClassIndex()) { case FLOAT: return ((RubyFloat) arg).getDoubleValue(); case FIXNUM: if (context.sites.Fixnum.to_f.isBuiltin(getMetaClass(arg))) return ((RubyFixnum) arg).getDoubleValue(); break; case BIGNUM: if (context.sites.Bignum.to_f.isBuiltin(getMetaClass(arg))) return ((RubyBignum) arg).getDoubleValue(); break; case RATIONAL: if (context.sites.Rational.to_f.isBuiltin(getMetaClass(arg))) return ((RubyRational) arg).getDoubleValue(); break; case STRING: case NIL: case TRUE: case FALSE: throw context.runtime.newTypeError(str(context.runtime, "can't convert ", arg.inspect(), " into Float")); } IRubyObject val = TypeConverter.convertToType(arg, context.runtime.getFloat(), "to_f"); return ((RubyFloat) val).getDoubleValue(); }