rational.c: inline `mrb_rational_eq()`.

It removes non-static function, so that strictly saying, it's
an incompatible change. But the function was added recently and I am
sure no one uses it yet.
parent 4a0c14e3
...@@ -354,18 +354,22 @@ rational_m(mrb_state *mrb, mrb_value self) ...@@ -354,18 +354,22 @@ rational_m(mrb_state *mrb, mrb_value self)
#endif #endif
} }
mrb_bool static mrb_value
mrb_rational_eq(mrb_state *mrb, mrb_value x, mrb_value y) rational_eq(mrb_state *mrb, mrb_value x)
{ {
mrb_value y = mrb_get_arg1(mrb);
struct mrb_rational *p1 = rational_ptr(mrb, x); struct mrb_rational *p1 = rational_ptr(mrb, x);
mrb_bool result;
switch (mrb_type(y)) { switch (mrb_type(y)) {
case MRB_TT_INTEGER: case MRB_TT_INTEGER:
if (p1->denominator != 1) return FALSE; if (p1->denominator != 1) return mrb_false_value();
return p1->numerator == mrb_integer(y); result = p1->numerator == mrb_integer(y);
break;
#ifndef MRB_NO_FLOAT #ifndef MRB_NO_FLOAT
case MRB_TT_FLOAT: case MRB_TT_FLOAT:
return ((double)p1->numerator/p1->denominator) == mrb_float(y); result = ((double)p1->numerator/p1->denominator) == mrb_float(y);
break;
#endif #endif
case MRB_TT_RATIONAL: case MRB_TT_RATIONAL:
{ {
...@@ -373,39 +377,36 @@ mrb_rational_eq(mrb_state *mrb, mrb_value x, mrb_value y) ...@@ -373,39 +377,36 @@ mrb_rational_eq(mrb_state *mrb, mrb_value x, mrb_value y)
mrb_int a, b; mrb_int a, b;
if (p1->numerator == p2->numerator && p1->denominator == p2->denominator) { if (p1->numerator == p2->numerator && p1->denominator == p2->denominator) {
return TRUE; return mrb_true_value();
} }
if (mrb_int_mul_overflow(p1->numerator, p2->denominator, &a) || if (mrb_int_mul_overflow(p1->numerator, p2->denominator, &a) ||
mrb_int_mul_overflow(p2->numerator, p1->denominator, &b)) { mrb_int_mul_overflow(p2->numerator, p1->denominator, &b)) {
#ifdef MRB_NO_FLOAT #ifdef MRB_NO_FLOAT
rat_overflow(mrb); rat_overflow(mrb);
#else #else
return (double)p1->numerator*p2->denominator == (double)p2->numerator*p2->denominator; result = (double)p1->numerator*p2->denominator == (double)p2->numerator*p2->denominator;
break;
#endif #endif
} }
return a == b; result = a == b;
break;
} }
#ifdef MRB_USE_COMPLEX #ifdef MRB_USE_COMPLEX
case MRB_TT_COMPLEX: case MRB_TT_COMPLEX:
{ {
mrb_bool mrb_complex_eq(mrb_state *mrb, mrb_value, mrb_value); mrb_bool mrb_complex_eq(mrb_state *mrb, mrb_value, mrb_value);
return mrb_complex_eq(mrb, y, x); result = mrb_complex_eq(mrb, y, x);
break;
} }
#endif #endif
default: default:
return mrb_equal(mrb, y, x); result = mrb_equal(mrb, y, x);
break;
} }
return mrb_bool_value(result);
} }
static mrb_value
rational_eq(mrb_state *mrb, mrb_value x)
{
mrb_value y = mrb_get_arg1(mrb);
return mrb_bool_value(mrb_rational_eq(mrb, x, y));
}
#ifndef MRB_NO_FLOAT #ifndef MRB_NO_FLOAT
mrb_value mrb_complex_new(mrb_state *, mrb_float, mrb_float); mrb_value mrb_complex_new(mrb_state *, mrb_float, mrb_float);
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment