<=>(p1)
public
Show source
static VALUE
nurat_cmp(VALUE self, VALUE other)
{
if (RB_TYPE_P(other, T_FIXNUM) || RB_TYPE_P(other, T_BIGNUM)) {
{
get_dat1(self);
if (FIXNUM_P(dat->den) && FIX2LONG(dat->den) == 1)
return f_cmp(dat->num, other); /* c14n */
return f_cmp(self, f_rational_new_bang1(CLASS_OF(self), other));
}
}
else if (RB_TYPE_P(other, T_FLOAT)) {
return f_cmp(f_to_f(self), other);
}
else if (RB_TYPE_P(other, T_RATIONAL)) {
{
VALUE num1, num2;
get_dat2(self, other);
if (FIXNUM_P(adat->num) && FIXNUM_P(adat->den) &&
FIXNUM_P(bdat->num) && FIXNUM_P(bdat->den)) {
num1 = f_imul(FIX2LONG(adat->num), FIX2LONG(bdat->den));
num2 = f_imul(FIX2LONG(bdat->num), FIX2LONG(adat->den));
}
else {
num1 = f_mul(adat->num, bdat->den);
num2 = f_mul(bdat->num, adat->den);
}
return f_cmp(f_sub(num1, num2), ZERO);
}
}
else {
return rb_num_coerce_cmp(self, other, id_cmp);
}
}