diff --git a/src/kernel.c b/src/kernel.c index 336aae670..e6368e397 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -61,6 +61,38 @@ mrb_obj_inspect(mrb_state *mrb, mrb_value obj) return mrb_any_to_s(mrb, obj); } +MRB_API mrb_bool +mrb_equal(mrb_state *mrb, mrb_value obj1, mrb_value obj2) +{ + mrb_value result; + + if (mrb_obj_eq(mrb, obj1, obj2)) return TRUE; +#ifndef MRB_NO_FLOAT + /* value mixing with integer and float */ + if (mrb_integer_p(obj1) && mrb_float_p(obj2)) { + if ((mrb_float)mrb_integer(obj1) == mrb_float(obj2)) + return TRUE; + return FALSE; + } + else if (mrb_float_p(obj1) && mrb_integer_p(obj2)) { + if (mrb_float(obj1) == (mrb_float)mrb_integer(obj2)) + return TRUE; + return FALSE; + } +#endif +#ifdef MRB_USE_BIGINT + if (mrb_bigint_p(obj1) && + (mrb_integer_p(obj2) || mrb_bigint_p(obj2) || mrb_float_p(obj2))) { + if (mrb_bint_cmp(mrb, obj1, obj2) == 0) + return TRUE; + return FALSE; + } +#endif + result = mrb_funcall_argv(mrb, obj1, MRB_OPSYM(eq), 1, &obj2); + if (mrb_test(result)) return TRUE; + return FALSE; +} + /* 15.3.1.3.2 */ /* * call-seq: diff --git a/src/object.c b/src/object.c index 0ca2e7b4d..61357175e 100644 --- a/src/object.c +++ b/src/object.c @@ -50,38 +50,6 @@ mrb_obj_equal(mrb_state *mrb, mrb_value v1, mrb_value v2) return mrb_obj_eq(mrb, v1, v2); } -MRB_API mrb_bool -mrb_equal(mrb_state *mrb, mrb_value obj1, mrb_value obj2) -{ - mrb_value result; - - if (mrb_obj_eq(mrb, obj1, obj2)) return TRUE; -#ifndef MRB_NO_FLOAT - /* value mixing with integer and float */ - if (mrb_integer_p(obj1) && mrb_float_p(obj2)) { - if ((mrb_float)mrb_integer(obj1) == mrb_float(obj2)) - return TRUE; - return FALSE; - } - else if (mrb_float_p(obj1) && mrb_integer_p(obj2)) { - if (mrb_float(obj1) == (mrb_float)mrb_integer(obj2)) - return TRUE; - return FALSE; - } -#endif -#ifdef MRB_USE_BIGINT - if (mrb_bigint_p(obj1) && - (mrb_integer_p(obj2) || mrb_bigint_p(obj2) || mrb_float_p(obj2))) { - if (mrb_bint_cmp(mrb, obj1, obj2) == 0) - return TRUE; - return FALSE; - } -#endif - result = mrb_funcall_argv(mrb, obj1, MRB_OPSYM(eq), 1, &obj2); - if (mrb_test(result)) return TRUE; - return FALSE; -} - /* * Document-class: NilClass *