/** flo_truncate * */ @JRubyMethod(name = {"truncate", "to_i", "to_int"}) @Override public IRubyObject truncate() { double f = value; if (f > 0.0) f = Math.floor(f); if (f < 0.0) f = Math.ceil(f); return dbl2num(getRuntime(), f); }
/** flo_truncate * */ @JRubyMethod(name = {"truncate", "to_i", "to_int"}) @Override public IRubyObject truncate() { double f = value; if (f > 0.0) f = Math.floor(f); if (f < 0.0) f = Math.ceil(f); return dbl2num(getRuntime(), f); }
/** flo_ceil * */ @JRubyMethod(name = "ceil") @Override public IRubyObject ceil() { return dbl2num(getRuntime(), Math.ceil(value)); }
/** flo_ceil * */ @JRubyMethod(name = "ceil") @Override public IRubyObject ceil() { return dbl2num(getRuntime(), Math.ceil(value)); }
/** floor * */ @JRubyMethod(name = "floor") @Override public IRubyObject floor() { return dbl2num(getRuntime(), Math.floor(value)); }
/** floor * */ @JRubyMethod(name = "floor") @Override public IRubyObject floor() { return dbl2num(getRuntime(), Math.floor(value)); }
/** flo_round * */ @JRubyMethod(name = "round") @Override public IRubyObject round() { return dbl2num(getRuntime(), val2dbl()); }
/** flo_round * */ @JRubyMethod(name = "round") @Override public IRubyObject round() { return dbl2num(getRuntime(), val2dbl()); }
f = Math.pow(10, ndigits); f = Math.floor(number * f) / f; return dbl2num(runtime, f); } else { RubyInteger num = dbl2ival(runtime, Math.floor(number));
f = Math.pow(10, ndigits); f = Math.floor(number * f) / f; return dbl2num(runtime, f); } else { RubyInteger num = dbl2ival(runtime, Math.floor(number));
/** flo_divmod * */ @JRubyMethod(name = "divmod", required = 1, compat = CompatVersion.RUBY1_8) @Override public IRubyObject divmod(ThreadContext context, IRubyObject other) { switch (other.getMetaClass().index) { case ClassIndex.FIXNUM: case ClassIndex.BIGNUM: case ClassIndex.FLOAT: double y = ((RubyNumeric) other).getDoubleValue(); double x = value; double mod = Math.IEEEremainder(x, y); // MRI behavior: if (Double.isNaN(mod)) { throw getRuntime().newFloatDomainError("NaN"); } double div = Math.floor(x / y); if (y * mod < 0) { mod += y; } final Ruby runtime = getRuntime(); IRubyObject car = dbl2num(runtime, div); RubyFloat cdr = RubyFloat.newFloat(runtime, mod); return RubyArray.newArray(runtime, car, cdr); default: return coerceBin(context, "divmod", other); } }
/** flo_divmod * */ @JRubyMethod(name = "divmod", required = 1, compat = CompatVersion.RUBY1_8) @Override public IRubyObject divmod(ThreadContext context, IRubyObject other) { switch (other.getMetaClass().index) { case ClassIndex.FIXNUM: case ClassIndex.BIGNUM: case ClassIndex.FLOAT: double y = ((RubyNumeric) other).getDoubleValue(); double x = value; double mod = Math.IEEEremainder(x, y); // MRI behavior: if (Double.isNaN(mod)) { throw getRuntime().newFloatDomainError("NaN"); } double div = Math.floor(x / y); if (y * mod < 0) { mod += y; } final Ruby runtime = getRuntime(); IRubyObject car = dbl2num(runtime, div); RubyFloat cdr = RubyFloat.newFloat(runtime, mod); return RubyArray.newArray(runtime, car, cdr); default: return coerceBin(context, "divmod", other); } }