diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-03-18 16:27:35 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-03-19 10:37:10 +0900 |
| commit | 08f9d5bab5092fe1193dd100765079e3e4d746b9 (patch) | |
| tree | 627588dd204f5a7c24ea79ab17076f3eeab818eb /src/object.c | |
| parent | eb070303080b24458d3740424aa7aa8a45fa49eb (diff) | |
| download | mruby-08f9d5bab5092fe1193dd100765079e3e4d746b9.tar.gz mruby-08f9d5bab5092fe1193dd100765079e3e4d746b9.zip | |
rational.c: overhaul rational operators.
- define `MRB_TT_RATIONAL`
- change object structure (`struct RRational`)
- add memory management for `MRB_TT_RATIONAL`
- avoid operator overloading as much as possible
- implement division overloading in C
- as a result, performance improved a lot
Diffstat (limited to 'src/object.c')
| -rw-r--r-- | src/object.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/object.c b/src/object.c index 0c6b86630..a44eab4bb 100644 --- a/src/object.c +++ b/src/object.c @@ -516,7 +516,10 @@ mrb_to_int(mrb_state *mrb, mrb_value val) return mrb_flo_to_fixnum(mrb, val); } #endif - mrb_raisef(mrb, E_TYPE_ERROR, "can't convert %Y to Integer", val); + if (mrb_string_p(val)) { + mrb_raise(mrb, E_TYPE_ERROR, "can't convert String to Integer"); + } + return mrb_type_convert(mrb, val, MRB_TT_INTEGER, MRB_SYM(to_i)); } return val; } |
