org.jruby.Ruby.newFloat()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(6.8k)|赞(0)|评价(0)|浏览(209)

本文整理了Java中org.jruby.Ruby.newFloat方法的一些代码示例,展示了Ruby.newFloat的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ruby.newFloat方法的具体详情如下:
包路径:org.jruby.Ruby
类名称:Ruby
方法名:newFloat

Ruby.newFloat介绍

暂无

代码示例

代码示例来源:origin: bazelbuild/bazel

  1. RubyBignum.newBignum(runtime, UINT64_COMPLEMENTARY.add(new BigInteger(ret + "")));
  2. case FLOAT:
  3. return runtime.newFloat((Float) value);
  4. case DOUBLE:
  5. return runtime.newFloat((Double) value);
  6. case BOOL:
  7. return (Boolean) value ? runtime.getTrue() : runtime.getFalse();

代码示例来源:origin: org.jruby/jruby-complete

  1. public static IRubyObject safe_mul(ThreadContext context, IRubyObject a, IRubyObject b, boolean az, boolean bz) {
  2. Ruby runtime = context.runtime;
  3. double v;
  4. if (!az && bz && a instanceof RubyFloat && !Double.isNaN(v = ((RubyFloat)a).getDoubleValue())) {
  5. a = v < 0.0d ? runtime.newFloat(-1.0d) : runtime.newFloat(1.0d);
  6. }
  7. if (!bz && az && b instanceof RubyFloat && !Double.isNaN(v = ((RubyFloat)b).getDoubleValue())) {
  8. b = v < 0.0d ? runtime.newFloat(-1.0) : runtime.newFloat(1.0);
  9. }
  10. return f_mul(context, a, b);
  11. }

代码示例来源:origin: org.jruby/jruby-core

  1. public static IRubyObject safe_mul(ThreadContext context, IRubyObject a, IRubyObject b, boolean az, boolean bz) {
  2. Ruby runtime = context.runtime;
  3. double v;
  4. if (!az && bz && a instanceof RubyFloat && !Double.isNaN(v = ((RubyFloat)a).getDoubleValue())) {
  5. a = v < 0.0d ? runtime.newFloat(-1.0d) : runtime.newFloat(1.0d);
  6. }
  7. if (!bz && az && b instanceof RubyFloat && !Double.isNaN(v = ((RubyFloat)b).getDoubleValue())) {
  8. b = v < 0.0d ? runtime.newFloat(-1.0) : runtime.newFloat(1.0);
  9. }
  10. return f_mul(context, a, b);
  11. }

代码示例来源:origin: org.jruby/jruby-complete

  1. private static IRubyObject makeClockResolutionResult(Ruby runtime, long nanos, String unit) {
  2. if (unit.equals(CLOCK_UNIT_HERTZ)) {
  3. return runtime.newFloat(1000000000.0 / nanos);
  4. } else {
  5. return makeClockResult(runtime, nanos, unit);
  6. }
  7. }

代码示例来源:origin: org.jruby/jruby-core

  1. private static IRubyObject makeClockResolutionResult(Ruby runtime, long nanos, String unit) {
  2. if (unit.equals(CLOCK_UNIT_HERTZ)) {
  3. return runtime.newFloat(1000000000.0 / nanos);
  4. } else {
  5. return makeClockResult(runtime, nanos, unit);
  6. }
  7. }

代码示例来源:origin: org.jruby/jruby-complete

  1. @JRubyMethod(name = "to_f")
  2. public static IRubyObject to_f(final ThreadContext context, final IRubyObject self) {
  3. java.lang.Number val = (java.lang.Number) self.toJava(java.lang.Number.class);
  4. return context.runtime.newFloat(val.doubleValue());
  5. }

代码示例来源:origin: org.jruby/jruby-core

  1. @JRubyMethod(name = "to_f")
  2. public static IRubyObject to_f(final ThreadContext context, final IRubyObject self) {
  3. java.lang.Number val = (java.lang.Number) self.toJava(java.lang.Number.class);
  4. return context.runtime.newFloat(val.doubleValue());
  5. }

代码示例来源:origin: org.jruby/jruby-complete

  1. final RubyFloat fdivDouble(ThreadContext context, RubyBignum y) {
  2. double dx = getDoubleValue();
  3. double dy = RubyBignum.big2dbl(y);
  4. if (Double.isInfinite(dx) || Double.isInfinite(dy)) {
  5. return (RubyFloat) fdivInt(context, y);
  6. }
  7. return context.runtime.newFloat(dx / dy);
  8. }

代码示例来源:origin: org.jruby/jruby-core

  1. final RubyFloat fdivDouble(ThreadContext context, RubyBignum y) {
  2. double dx = getDoubleValue();
  3. double dy = RubyBignum.big2dbl(y);
  4. if (Double.isInfinite(dx) || Double.isInfinite(dy)) {
  5. return (RubyFloat) fdivInt(context, y);
  6. }
  7. return context.runtime.newFloat(dx / dy);
  8. }

代码示例来源:origin: org.jruby/jruby-complete

  1. /** nurat_to_f
  2. *
  3. */
  4. @JRubyMethod(name = "to_f")
  5. public IRubyObject to_f(ThreadContext context) {
  6. return context.runtime.newFloat(getDoubleValue(context));
  7. }

代码示例来源:origin: org.jruby/jruby-core

  1. /** nurat_to_f
  2. *
  3. */
  4. @JRubyMethod(name = "to_f")
  5. public IRubyObject to_f(ThreadContext context) {
  6. return context.runtime.newFloat(getDoubleValue(context));
  7. }

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

  1. public static RubyFloat initFloat(MutableCallSite site, ThreadContext context, double value) {
  2. RubyFloat rubyFloat = context.runtime.newFloat(value);
  3. site.setTarget(dropArguments(constant(RubyFloat.class, rubyFloat), 0, ThreadContext.class));
  4. return rubyFloat;
  5. }

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

  1. private IRubyObject addOther(ThreadContext context, IRubyObject other) {
  2. if (other instanceof RubyBignum) {
  3. return ((RubyBignum) other).op_plus(context, this);
  4. }
  5. if (other instanceof RubyFloat) {
  6. return context.runtime.newFloat((double) value + ((RubyFloat) other).getDoubleValue());
  7. }
  8. return coerceBin(context, "+", other);
  9. }

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

  1. public static RubyFloat initFloat(MutableCallSite site, ThreadContext context, double value) {
  2. RubyFloat rubyFloat = context.runtime.newFloat(value);
  3. site.setTarget(dropArguments(constant(RubyFloat.class, rubyFloat), 0, ThreadContext.class));
  4. return rubyFloat;
  5. }

代码示例来源:origin: org.jruby/jruby-complete

  1. private IRubyObject addOther(ThreadContext context, IRubyObject other) {
  2. if (other instanceof RubyBignum) {
  3. return ((RubyBignum) other).op_plus(context, this.value);
  4. }
  5. if (other instanceof RubyFloat) {
  6. return context.runtime.newFloat((double) value + ((RubyFloat) other).getDoubleValue());
  7. }
  8. return coerceBin(context, sites(context).op_plus, other);
  9. }

代码示例来源:origin: org.jruby/jruby-complete

  1. private IRubyObject multiplyOther(ThreadContext context, IRubyObject other) {
  2. Ruby runtime = context.runtime;
  3. if (other instanceof RubyBignum) {
  4. return ((RubyBignum) other).op_mul(context, this.value);
  5. }
  6. if (other instanceof RubyFloat) {
  7. return runtime.newFloat((double) value * ((RubyFloat) other).getDoubleValue());
  8. }
  9. return coerceBin(context, sites(context).op_times, other);
  10. }

代码示例来源:origin: org.jruby/jruby-core

  1. private IRubyObject multiplyOther(ThreadContext context, IRubyObject other) {
  2. Ruby runtime = context.runtime;
  3. if (other instanceof RubyBignum) {
  4. return ((RubyBignum) other).op_mul(context, this.value);
  5. }
  6. if (other instanceof RubyFloat) {
  7. return runtime.newFloat((double) value * ((RubyFloat) other).getDoubleValue());
  8. }
  9. return coerceBin(context, sites(context).op_times, other);
  10. }

代码示例来源:origin: org.jruby/jruby-core

  1. private IRubyObject addOther(ThreadContext context, IRubyObject other) {
  2. if (other instanceof RubyBignum) {
  3. return ((RubyBignum) other).op_plus(context, this.value);
  4. }
  5. if (other instanceof RubyFloat) {
  6. return context.runtime.newFloat((double) value + ((RubyFloat) other).getDoubleValue());
  7. }
  8. return coerceBin(context, sites(context).op_plus, other);
  9. }

代码示例来源:origin: org.jruby/jruby-core

  1. private IRubyObject subtractOther(ThreadContext context, IRubyObject other) {
  2. if (other instanceof RubyBignum) {
  3. return RubyBignum.newBignum(context.runtime, value).op_minus(context, ((RubyBignum) other).value);
  4. }
  5. if (other instanceof RubyFloat) {
  6. return context.runtime.newFloat((double) value - ((RubyFloat) other).getDoubleValue());
  7. }
  8. return coerceBin(context, sites(context).op_minus, other);
  9. }

代码示例来源:origin: org.jruby/jruby-complete

  1. private IRubyObject subtractOther(ThreadContext context, IRubyObject other) {
  2. if (other instanceof RubyBignum) {
  3. return RubyBignum.newBignum(context.runtime, value).op_minus(context, ((RubyBignum) other).value);
  4. }
  5. if (other instanceof RubyFloat) {
  6. return context.runtime.newFloat((double) value - ((RubyFloat) other).getDoubleValue());
  7. }
  8. return coerceBin(context, sites(context).op_minus, other);
  9. }

相关文章

Ruby类方法