<=>(p1)
public
Returns -1, 0, +1 or nil depending on whether flt is less than,
equal to, or greater than real. This is the basis for the tests in
Comparable.
Show source
static VALUE
flo_cmp(VALUE x, VALUE y)
{
double a, b;
VALUE i;
a = RFLOAT_VALUE(x);
if (isnan(a)) return Qnil;
switch (TYPE(y)) {
case T_FIXNUM:
b = (double)FIX2LONG(y);
break;
case T_BIGNUM:
if (isinf(a)) {
if (a > 0.0) return INT2FIX(1);
else return INT2FIX(-1);
}
b = rb_big2dbl(y);
break;
case T_FLOAT:
b = RFLOAT_VALUE(y);
break;
default:
if (isinf(a) && (i = rb_check_funcall(y, rb_intern("infinite?"), 0, 0)) != Qundef) {
if (RTEST(i)) {
int j = rb_cmpint(i, x, y);
j = (a > 0.0) ? (j > 0 ? 0 : +1) : (j < 0 ? 0 : -1);
return INT2FIX(j);
}
if (a > 0.0) return INT2FIX(1);
return INT2FIX(-1);
}
return rb_num_coerce_cmp(x, y, rb_intern("<=>"));
}
return rb_dbl_cmp(a, b);
}