@Override public final int compareTo(IRubyObject other) { if (other instanceof RubyBignum) { return value.compareTo(((RubyBignum)other).value); } return (int)coerceCmp(getRuntime().getCurrentContext(), "<=>", other).convertToInteger().getLongValue(); }
@Override public final int compareTo(IRubyObject other) { if (other instanceof RubyBignum) { return value.compareTo(((RubyBignum)other).value); } return (int)coerceCmp(getRuntime().getCurrentContext(), "<=>", other).convertToInteger().getLongValue(); }
@Override public final int compareTo(IRubyObject other) { if (other instanceof RubyBignum) { return value.compareTo(((RubyBignum)other).value); } ThreadContext context = getRuntime().getCurrentContext(); return (int)coerceCmp(context, sites(context).op_cmp, other).convertToInteger().getLongValue(); }
@Override public final int compareTo(IRubyObject other) { if (other instanceof RubyBignum) { return value.compareTo(((RubyBignum)other).value); } ThreadContext context = getRuntime().getCurrentContext(); return (int)coerceCmp(context, sites(context).op_cmp, other).convertToInteger().getLongValue(); }
/** rb_big_cmp * */ @Override public IRubyObject op_cmp(ThreadContext context, IRubyObject other) { final BigInteger otherValue; if (other instanceof RubyFixnum) { otherValue = fix2big((RubyFixnum) other); } else if (other instanceof RubyBignum) { otherValue = ((RubyBignum) other).value; } else if (other instanceof RubyFloat) { RubyFloat flt = (RubyFloat)other; if (flt.infinite_p().isTrue()) { if (flt.getDoubleValue() > 0.0) return RubyFixnum.minus_one(context.runtime); return RubyFixnum.one(context.runtime); } return dbl_cmp(context.runtime, big2dbl(this), flt.getDoubleValue()); } else { return coerceCmp(context, sites(context).op_cmp, other); } // wow, the only time we can use the java protocol ;) return RubyFixnum.newFixnum(context.runtime, value.compareTo(otherValue)); }
/** rb_big_cmp * */ @Override public IRubyObject op_cmp(ThreadContext context, IRubyObject other) { final BigInteger otherValue; if (other instanceof RubyFixnum) { otherValue = fix2big((RubyFixnum) other); } else if (other instanceof RubyBignum) { otherValue = ((RubyBignum) other).value; } else if (other instanceof RubyFloat) { RubyFloat flt = (RubyFloat)other; if (flt.infinite_p().isTrue()) { if (flt.getDoubleValue() > 0.0) return RubyFixnum.minus_one(context.runtime); return RubyFixnum.one(context.runtime); } return dbl_cmp(context.runtime, big2dbl(this), flt.getDoubleValue()); } else { return coerceCmp(context, sites(context).op_cmp, other); } // wow, the only time we can use the java protocol ;) return RubyFixnum.newFixnum(context.runtime, value.compareTo(otherValue)); }
/** rb_big_cmp * */ @JRubyMethod(name = "<=>", required = 1) public IRubyObject op_cmp(ThreadContext context, IRubyObject other) { final BigInteger otherValue; if (other instanceof RubyFixnum) { otherValue = fix2big((RubyFixnum) other); } else if (other instanceof RubyBignum) { otherValue = ((RubyBignum) other).value; } else if (other instanceof RubyFloat) { RubyFloat flt = (RubyFloat)other; if (flt.infinite_p().isTrue()) { if (flt.getDoubleValue() > 0.0) return RubyFixnum.minus_one(getRuntime()); return RubyFixnum.one(getRuntime()); } return dbl_cmp(getRuntime(), big2dbl(this), flt.getDoubleValue()); } else { return coerceCmp(context, "<=>", other); } // wow, the only time we can use the java protocol ;) return RubyFixnum.newFixnum(getRuntime(), value.compareTo(otherValue)); }
/** rb_big_cmp * */ @JRubyMethod(name = "<=>", required = 1) public IRubyObject op_cmp(ThreadContext context, IRubyObject other) { final BigInteger otherValue; if (other instanceof RubyFixnum) { otherValue = fix2big((RubyFixnum) other); } else if (other instanceof RubyBignum) { otherValue = ((RubyBignum) other).value; } else if (other instanceof RubyFloat) { RubyFloat flt = (RubyFloat)other; if (flt.infinite_p().isTrue()) { if (flt.getDoubleValue() > 0.0) return RubyFixnum.minus_one(getRuntime()); return RubyFixnum.one(getRuntime()); } return dbl_cmp(getRuntime(), big2dbl(this), flt.getDoubleValue()); } else { return coerceCmp(context, "<=>", other); } // wow, the only time we can use the java protocol ;) return RubyFixnum.newFixnum(getRuntime(), value.compareTo(otherValue)); }