diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2020-06-20 18:56:05 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2020-06-20 18:56:05 +0900 |
| commit | 28e793496a4be0609837e25aa16a3f3ebe402e33 (patch) | |
| tree | 2882f86bb0ad081bcfe7d9af91aa5bb5d6e2564b | |
| parent | 33c8d6af1e2b18abf27d3fcacfdc6aef29387b23 (diff) | |
| download | mruby-28e793496a4be0609837e25aa16a3f3ebe402e33.tar.gz mruby-28e793496a4be0609837e25aa16a3f3ebe402e33.zip | |
Support integer and float combination in `mrb_equal()`.
| -rw-r--r-- | src/object.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/object.c b/src/object.c index cc62343a1..db9dfb568 100644 --- a/src/object.c +++ b/src/object.c @@ -47,6 +47,17 @@ 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_WITHOUT_FLOAT + /* value mixing with integer and float */ + if (mrb_fixnum_p(obj1)) { + if (mrb_float_p(obj2) && (mrb_float)mrb_fixnum(obj1) == mrb_float(obj2)) + return TRUE; + } + else if (mrb_float_p(obj1)) { + if (mrb_fixnum_p(obj2) && mrb_float(obj1) == (mrb_float)mrb_fixnum(obj2)) + return TRUE; + } +#endif result = mrb_funcall(mrb, obj1, "==", 1, obj2); if (mrb_test(result)) return TRUE; return FALSE; |
