<=>(p1)
public
Comparison—Returns -1, 0, or +1 depending on whether big is less
than, equal to, or greater than numeric. This is the basis for the
tests in Comparable.
nil is returned if the two values are incomparable.
Show source
VALUE
rb_big_cmp(VALUE x, VALUE y)
{
int cmp;
if (FIXNUM_P(y)) {
x = bignorm(x);
if (FIXNUM_P(x)) {
if (FIX2LONG(x) > FIX2LONG(y)) return INT2FIX(1);
if (FIX2LONG(x) < FIX2LONG(y)) return INT2FIX(-1);
return INT2FIX(0);
}
else {
if (BIGNUM_NEGATIVE_P(x)) return INT2FIX(-1);
return INT2FIX(1);
}
}
else if (RB_BIGNUM_TYPE_P(y)) {
}
else if (RB_FLOAT_TYPE_P(y)) {
return rb_integer_float_cmp(x, y);
}
else {
return rb_num_coerce_cmp(x, y, rb_intern("<=>"));
}
if (BIGNUM_SIGN(x) > BIGNUM_SIGN(y)) return INT2FIX(1);
if (BIGNUM_SIGN(x) < BIGNUM_SIGN(y)) return INT2FIX(-1);
cmp = bary_cmp(BDIGITS(x), BIGNUM_LEN(x), BDIGITS(y), BIGNUM_LEN(y));
if (BIGNUM_SIGN(x))
return INT2FIX(cmp);
else
return INT2FIX(-cmp);
}