public static IRubyObject safe_mul(ThreadContext context, IRubyObject a, IRubyObject b, boolean az, boolean bz) { Ruby runtime = context.runtime; double v; if (!az && bz && a instanceof RubyFloat && !Double.isNaN(v = ((RubyFloat)a).getDoubleValue())) { a = v < 0.0d ? runtime.newFloat(-1.0d) : runtime.newFloat(1.0d); } if (!bz && az && b instanceof RubyFloat && !Double.isNaN(v = ((RubyFloat)b).getDoubleValue())) { b = v < 0.0d ? runtime.newFloat(-1.0) : runtime.newFloat(1.0); } return f_mul(context, a, b); }
public static IRubyObject safe_mul(ThreadContext context, IRubyObject a, IRubyObject b, boolean az, boolean bz) { Ruby runtime = context.runtime; double v; if (!az && bz && a instanceof RubyFloat && !Double.isNaN(v = ((RubyFloat)a).getDoubleValue())) { a = v < 0.0d ? runtime.newFloat(-1.0d) : runtime.newFloat(1.0d); } if (!bz && az && b instanceof RubyFloat && !Double.isNaN(v = ((RubyFloat)b).getDoubleValue())) { b = v < 0.0d ? runtime.newFloat(-1.0) : runtime.newFloat(1.0); } return f_mul(context, a, b); }
private static IRubyObject makeClockResolutionResult(Ruby runtime, long nanos, String unit) { if (unit.equals(CLOCK_UNIT_HERTZ)) { return runtime.newFloat(1000000000.0 / nanos); } else { return makeClockResult(runtime, nanos, unit); } }
private static IRubyObject makeClockResolutionResult(Ruby runtime, long nanos, String unit) { if (unit.equals(CLOCK_UNIT_HERTZ)) { return runtime.newFloat(1000000000.0 / nanos); } else { return makeClockResult(runtime, nanos, unit); } }
@JRubyMethod(name = "to_f") public static IRubyObject to_f(final ThreadContext context, final IRubyObject self) { java.lang.Number val = (java.lang.Number) self.toJava(java.lang.Number.class); return context.runtime.newFloat(val.doubleValue()); }
@JRubyMethod(name = "to_f") public static IRubyObject to_f(final ThreadContext context, final IRubyObject self) { java.lang.Number val = (java.lang.Number) self.toJava(java.lang.Number.class); return context.runtime.newFloat(val.doubleValue()); }
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); }
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); }
/** nurat_to_f * */ @JRubyMethod(name = "to_f") public IRubyObject to_f(ThreadContext context) { return context.runtime.newFloat(getDoubleValue(context)); }
/** nurat_to_f * */ @JRubyMethod(name = "to_f") public IRubyObject to_f(ThreadContext context) { return context.runtime.newFloat(getDoubleValue(context)); }
public static RubyFloat initFloat(MutableCallSite site, ThreadContext context, double value) { RubyFloat rubyFloat = context.runtime.newFloat(value); site.setTarget(dropArguments(constant(RubyFloat.class, rubyFloat), 0, ThreadContext.class)); return rubyFloat; }
private IRubyObject addOther(ThreadContext context, IRubyObject other) { if (other instanceof RubyBignum) { return ((RubyBignum) other).op_plus(context, this); } if (other instanceof RubyFloat) { return context.runtime.newFloat((double) value + ((RubyFloat) other).getDoubleValue()); } return coerceBin(context, "+", other); }
public static RubyFloat initFloat(MutableCallSite site, ThreadContext context, double value) { RubyFloat rubyFloat = context.runtime.newFloat(value); site.setTarget(dropArguments(constant(RubyFloat.class, rubyFloat), 0, ThreadContext.class)); return rubyFloat; }
private IRubyObject addOther(ThreadContext context, IRubyObject other) { if (other instanceof RubyBignum) { return ((RubyBignum) other).op_plus(context, this.value); } if (other instanceof RubyFloat) { return context.runtime.newFloat((double) value + ((RubyFloat) other).getDoubleValue()); } return coerceBin(context, sites(context).op_plus, other); }
private IRubyObject multiplyOther(ThreadContext context, IRubyObject other) { Ruby runtime = context.runtime; if (other instanceof RubyBignum) { return ((RubyBignum) other).op_mul(context, this.value); } if (other instanceof RubyFloat) { return runtime.newFloat((double) value * ((RubyFloat) other).getDoubleValue()); } return coerceBin(context, sites(context).op_times, other); }
private IRubyObject multiplyOther(ThreadContext context, IRubyObject other) { Ruby runtime = context.runtime; if (other instanceof RubyBignum) { return ((RubyBignum) other).op_mul(context, this.value); } if (other instanceof RubyFloat) { return runtime.newFloat((double) value * ((RubyFloat) other).getDoubleValue()); } return coerceBin(context, sites(context).op_times, other); }
private IRubyObject addOther(ThreadContext context, IRubyObject other) { if (other instanceof RubyBignum) { return ((RubyBignum) other).op_plus(context, this.value); } if (other instanceof RubyFloat) { return context.runtime.newFloat((double) value + ((RubyFloat) other).getDoubleValue()); } return coerceBin(context, sites(context).op_plus, other); }
private IRubyObject subtractOther(ThreadContext context, IRubyObject other) { if (other instanceof RubyBignum) { return RubyBignum.newBignum(context.runtime, value).op_minus(context, ((RubyBignum) other).value); } if (other instanceof RubyFloat) { return context.runtime.newFloat((double) value - ((RubyFloat) other).getDoubleValue()); } return coerceBin(context, sites(context).op_minus, other); }
private IRubyObject subtractOther(ThreadContext context, IRubyObject other) { if (other instanceof RubyBignum) { return RubyBignum.newBignum(context.runtime, value).op_minus(context, ((RubyBignum) other).value); } if (other instanceof RubyFloat) { return context.runtime.newFloat((double) value - ((RubyFloat) other).getDoubleValue()); } return coerceBin(context, sites(context).op_minus, other); }