static long val2sg(ThreadContext context, IRubyObject sg) { return getValidStart(context, sg.convertToFloat().getDoubleValue(), ITALY); }
static long valid_sg(ThreadContext context, IRubyObject sg) { return getValidStart(context, sg.convertToFloat().getDoubleValue(), 0); }
static long val2sg(ThreadContext context, IRubyObject sg) { return getValidStart(context, sg.convertToFloat().getDoubleValue(), ITALY); }
static long valid_sg(ThreadContext context, IRubyObject sg) { return getValidStart(context, sg.convertToFloat().getDoubleValue(), 0); }
/** num_div * */ @JRubyMethod(name = "div", compat = RUBY1_8) public IRubyObject div(ThreadContext context, IRubyObject other) { return callMethod(context, "/", other).convertToFloat().floor(); }
/** num_div * */ @JRubyMethod(name = "div", compat = RUBY1_8) public IRubyObject div(ThreadContext context, IRubyObject other) { return callMethod(context, "/", other).convertToFloat().floor(); }
/** * Provides processing constrain method as a ruby module method * * @param context ThreadContext * @param recv IRubyObject * @param args array of args must be be numeric * @return original or limit values */ @JRubyMethod(name = "constrain", rest = true, module = true) public static IRubyObject constrainValue(ThreadContext context, IRubyObject recv, IRubyObject[] args) { RubyFloat value = args[0].convertToFloat(); RubyFloat start = args[1].convertToFloat(); RubyFloat stop = args[2].convertToFloat(); if (value.op_ge(context, start).isTrue() && value.op_le(context, stop).isTrue()) { return args[0]; } else if (value.op_ge(context, start).isTrue()) { return args[2]; } else { return args[1]; } }
@JRubyMethod(compat = CompatVersion.RUBY1_9) public IRubyObject sleep(ThreadContext context, IRubyObject timeout) { long beg = System.currentTimeMillis(); try { unlock(context); context.getThread().sleep((long) (timeout.convertToFloat().getDoubleValue() * 1000)); } catch (InterruptedException ex) { // ignore interrupted } finally { lock(context); } return context.runtime.newFixnum((System.currentTimeMillis() - beg) / 1000); }
@JRubyMethod(compat = CompatVersion.RUBY1_9) public IRubyObject sleep(ThreadContext context, IRubyObject timeout) { long beg = System.currentTimeMillis(); try { unlock(context); context.getThread().sleep((long) (timeout.convertToFloat().getDoubleValue() * 1000)); } catch (InterruptedException ex) { // ignore interrupted } finally { lock(context); } return context.runtime.newFixnum((System.currentTimeMillis() - beg) / 1000); }
throw context.runtime.newTypeError("can't convert " + args[0].getMetaClass().getName() + "into time interval"); milliseconds = (long) (args[0].convertToFloat().getDoubleValue() * 1000); if (milliseconds < 0) { throw context.runtime.newArgumentError("time interval must be positive");
throw context.runtime.newTypeError("can't convert " + args[0].getMetaClass().getName() + "into time interval"); milliseconds = (long) (args[0].convertToFloat().getDoubleValue() * 1000); if (milliseconds < 0) { throw context.runtime.newArgumentError("time interval must be positive");
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; }
try { timeoutFuture = timeoutExecutor.schedule(timeoutRunnable, (long)(seconds.convertToFloat().getDoubleValue() * 1000000), TimeUnit.MICROSECONDS);
try { timeoutFuture = timeoutExecutor.schedule(timeoutRunnable, (long)(seconds.convertToFloat().getDoubleValue() * 1000000), TimeUnit.MICROSECONDS);
throw e; // won't happen final double t = _timeout.convertToFloat().getDoubleValue(); if ( t < 0 ) throw context.runtime.newArgumentError("negative timeout"); timeout = (long) (t * 1000); // ms
throw e; // won't happen final double t = _timeout.convertToFloat().getDoubleValue(); if ( t < 0 ) throw context.runtime.newArgumentError("negative timeout"); timeout = (long) (t * 1000); // ms
try { timeoutFuture = timeoutExecutor.schedule(timeoutRunnable, (long)(seconds.convertToFloat().getDoubleValue() * 1000000), TimeUnit.MICROSECONDS);
if ( sec instanceof JavaProxy ) { try { // support java.lang.Number proxies seconds = sec.convertToFloat().getDoubleValue(); raise = false; } catch (TypeError ex) { /* fallback bellow to raising a TypeError */ }
if ( sec instanceof JavaProxy ) { try { // support java.lang.Number proxies seconds = sec.convertToFloat().getDoubleValue(); raise = false; } catch (TypeError ex) { /* fallback bellow to raising a TypeError */ }