public IRubyObject op_equal(ThreadContext context, double other) { if (Double.isNaN(value)) { return getRuntime().getFalse(); } return RubyBoolean.newBoolean(getRuntime(), value == other); }
public IRubyObject op_equal(ThreadContext context, double other) { if (Double.isNaN(value)) { return getRuntime().getFalse(); } return RubyBoolean.newBoolean(getRuntime(), value == other); }
/** flo_is_finite_p * */ @JRubyMethod(name = "finite?") public IRubyObject finite_p() { if (Double.isInfinite(value) || Double.isNaN(value)) { return getRuntime().getFalse(); } return getRuntime().getTrue(); }
/** flo_is_finite_p * */ @JRubyMethod(name = "finite?") public IRubyObject finite_p() { if (Double.isInfinite(value) || Double.isNaN(value)) { return getRuntime().getFalse(); } return getRuntime().getTrue(); }
/** flo_is_infinite_p * */ @JRubyMethod(name = "infinite?") public IRubyObject infinite_p() { if (Double.isInfinite(value)) { return RubyFixnum.newFixnum(getRuntime(), value < 0 ? -1 : 1); } return getRuntime().getNil(); }
/** flo_is_infinite_p * */ @JRubyMethod(name = "infinite?") public IRubyObject infinite_p() { if (Double.isInfinite(value)) { return RubyFixnum.newFixnum(getRuntime(), value < 0 ? -1 : 1); } return getRuntime().getNil(); }
public static long float2long(RubyFloat flt) { double aFloat = flt.getDoubleValue(); if (aFloat <= (double) Long.MAX_VALUE && aFloat >= (double) Long.MIN_VALUE) { return (long) aFloat; } // TODO: number formatting here, MRI uses "%-.10g", 1.4 API is a must? throw flt.getRuntime().newRangeError("float " + aFloat + " out of range of integer"); }
private ByteList marshalDump() { if (Double.isInfinite(value)) return value < 0 ? NEGATIVE_INFINITY_BYTELIST : INFINITY_BYTELIST; if (Double.isNaN(value)) return NAN_BYTELIST; ByteList byteList = new ByteList(); // Always use US locale, to ensure "." separator. JRUBY-5918 Sprintf.sprintf(byteList, Locale.US, "%.17g", RubyArray.newArray(getRuntime(), this)); return byteList; }
public static long float2long(RubyFloat flt) { double aFloat = flt.getDoubleValue(); if (aFloat <= (double) Long.MAX_VALUE && aFloat >= (double) Long.MIN_VALUE) { return (long) aFloat; } // TODO: number formatting here, MRI uses "%-.10g", 1.4 API is a must? throw flt.getRuntime().newRangeError("float " + aFloat + " out of range of integer"); }
/** flo_hash * */ @JRubyMethod(name = "hash") @Override public RubyFixnum hash() { return getRuntime().newFixnum( hashCode() ); }
/** flo_hash * */ @JRubyMethod(name = "hash") @Override public RubyFixnum hash() { return getRuntime().newFixnum(hashCode()); }
/** flo_round * */ @JRubyMethod(name = "round") @Override public IRubyObject round() { return dbl2num(getRuntime(), val2dbl()); }
/** flo_hash * */ @JRubyMethod(name = "hash") @Override public RubyFixnum hash() { return getRuntime().newFixnum(hashCode()); }
/** flo_round * */ @JRubyMethod(name = "round") @Override public IRubyObject round() { return dbl2num(getRuntime(), val2dbl()); }
/** flo_is_nan_p * */ @JRubyMethod(name = "nan?") public IRubyObject nan_p() { return RubyBoolean.newBoolean(getRuntime(), isNaN()); }
/** flo_hash * */ @JRubyMethod(name = "hash") @Override public RubyFixnum hash() { return getRuntime().newFixnum( hashCode() ); }
/** flo_coerce * */ @JRubyMethod(name = "coerce", required = 1) @Override public IRubyObject coerce(IRubyObject other) { return getRuntime().newArray(RubyKernel.new_float(this, other), this); }
@JRubyMethod(name = "**", required = 1, compat = CompatVersion.RUBY1_9) public IRubyObject op_pow19(ThreadContext context, IRubyObject other) { double d_other = ((RubyNumeric) other).getDoubleValue(); if (value < 0 && (d_other != Math.round(d_other))) { return RubyComplex.newComplexRaw(getRuntime(), this).callMethod(context, "**", other); } else { return op_pow(context, other); } }
@Override public final int compareTo(IRubyObject other) { switch (other.getMetaClass().index) { case ClassIndex.FIXNUM: case ClassIndex.BIGNUM: case ClassIndex.FLOAT: return Double.compare(value, ((RubyNumeric) other).getDoubleValue()); default: return (int)coerceCmp(getRuntime().getCurrentContext(), "<=>", other).convertToInteger().getLongValue(); } }
@Override public final int compareTo(IRubyObject other) { switch (other.getMetaClass().getClassIndex()) { case INTEGER: case FLOAT: return Double.compare(value, ((RubyNumeric) other).getDoubleValue()); default: ThreadContext context = getRuntime().getCurrentContext(); return (int) coerceCmp(context, sites(context).op_cmp, other).convertToInteger().getLongValue(); } }