protected RubyFloat toFloat() { return RubyFloat.newFloat(getRuntime(), getDoubleValue()); }
protected RubyFloat toFloat() { return RubyFloat.newFloat(getRuntime(), getDoubleValue()); }
protected RubyFloat toFloat() { return RubyFloat.newFloat(getRuntime(), getDoubleValue()); }
protected RubyFloat toFloat() { return RubyFloat.newFloat(getRuntime(), getDoubleValue()); }
@JRubyMethod(name = "quo", required = 1, compat = RUBY1_9) public IRubyObject quo19(ThreadContext context, IRubyObject other) { if (other instanceof RubyInteger && ((RubyInteger) other).getDoubleValue() == 0) { throw context.runtime.newZeroDivisionError(); } return quo(context, other); }
@JRubyMethod(name = "quo", required = 1, compat = RUBY1_9) public IRubyObject quo19(ThreadContext context, IRubyObject other) { if (other instanceof RubyInteger && ((RubyInteger) other).getDoubleValue() == 0) { throw context.runtime.newZeroDivisionError(); } return quo(context, other); }
private static long convertTimeout(final ThreadContext context, IRubyObject timeoutArg) { final long timeout; if (timeoutArg instanceof RubyFloat) { timeout = Math.round(((RubyFloat) timeoutArg).getDoubleValue() * 1000); } else if (timeoutArg instanceof RubyInteger) { timeout = Math.round(((RubyInteger) timeoutArg).getDoubleValue() * 1000); } else { final Ruby runtime = context.runtime; if ( ! runtime.is1_8() ) { RubyFloat t = null; try { t = timeoutArg.callMethod(context, "to_f").convertToFloat(); } catch (RaiseException e) { /* fallback to TypeError */ } timeout = t != null ? Math.round(t.getDoubleValue() * 1000) : -1; } else timeout = -1; if ( timeout == -1 ) { throw runtime.newTypeError("can't convert " + timeoutArg.getMetaClass().getName() + " into time interval"); } } if ( timeout < 0 ) throw context.runtime.newArgumentError("negative timeout given"); return timeout; }
private static long convertTimeout(final ThreadContext context, IRubyObject timeoutArg) { final long timeout; if (timeoutArg instanceof RubyFloat) { timeout = Math.round(((RubyFloat) timeoutArg).getDoubleValue() * 1000); } else if (timeoutArg instanceof RubyInteger) { timeout = Math.round(((RubyInteger) timeoutArg).getDoubleValue() * 1000); } else { final Ruby runtime = context.runtime; if ( ! runtime.is1_8() ) { RubyFloat t = null; try { t = timeoutArg.callMethod(context, "to_f").convertToFloat(); } catch (RaiseException e) { /* fallback to TypeError */ } timeout = t != null ? Math.round(t.getDoubleValue() * 1000) : -1; } else timeout = -1; if ( timeout == -1 ) { throw runtime.newTypeError("can't convert " + timeoutArg.getMetaClass().getName() + " into time interval"); } } if ( timeout < 0 ) throw context.runtime.newArgumentError("negative timeout given"); return timeout; }
/** rb_big_quo * */ @Override @JRubyMethod(name = "quo", required = 1) public IRubyObject quo(ThreadContext context, IRubyObject other) { if (other instanceof RubyInteger && ((RubyInteger) other).getDoubleValue() == 0) { throw context.runtime.newZeroDivisionError(); } if (other instanceof RubyNumeric) { if (((RubyNumeric) other).getDoubleValue() == 0) { throw context.runtime.newZeroDivisionError(); } return RubyFloat.newFloat(context.runtime, big2dbl(this) / ((RubyNumeric) other).getDoubleValue()); } else { return coerceBin(context, sites(context).quo, other); } }
/** rb_big_quo * */ @Override @JRubyMethod(name = "quo", required = 1) public IRubyObject quo(ThreadContext context, IRubyObject other) { if (other instanceof RubyInteger && ((RubyInteger) other).getDoubleValue() == 0) { throw context.runtime.newZeroDivisionError(); } if (other instanceof RubyNumeric) { if (((RubyNumeric) other).getDoubleValue() == 0) { throw context.runtime.newZeroDivisionError(); } return RubyFloat.newFloat(context.runtime, big2dbl(this) / ((RubyNumeric) other).getDoubleValue()); } else { return coerceBin(context, sites(context).quo, other); } }