diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-03-24 10:42:32 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-03-24 10:54:24 +0900 |
| commit | ec456e5b1878ec2ef27ad479dc16e661f9483737 (patch) | |
| tree | f43b373b24606042469a59712454d1bf7a7cd68a /mrbgems/mruby-rational/src | |
| parent | 98799aa6b8cff160c510046b374ebec76fd6692c (diff) | |
| download | mruby-ec456e5b1878ec2ef27ad479dc16e661f9483737.tar.gz mruby-ec456e5b1878ec2ef27ad479dc16e661f9483737.zip | |
Use `mrb_num_div_flo` for float division.
This function handles zero division properly. Also fixed bugs that multiply
numbers instead of division.
Diffstat (limited to 'mrbgems/mruby-rational/src')
| -rw-r--r-- | mrbgems/mruby-rational/src/rational.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/mrbgems/mruby-rational/src/rational.c b/mrbgems/mruby-rational/src/rational.c index 497a36d8e..be9b5eaf9 100644 --- a/mrbgems/mruby-rational/src/rational.c +++ b/mrbgems/mruby-rational/src/rational.c @@ -406,7 +406,11 @@ rational_minus(mrb_state *mrb, mrb_value x) return rational_new(mrb, -p->numerator, p->denominator); } -mrb_int mrb_num_div_int(mrb_state *, mrb_int, mrb_int); +mrb_int mrb_num_div_int(mrb_state*, mrb_int, mrb_int); +mrb_value mrb_complex_new(mrb_state*, mrb_float, mrb_float); +#ifndef MRB_NO_FLOAT +mrb_float mrb_num_div_flo(mrb_state*, mrb_float, mrb_float); +#endif /* 15.2.8.3.4 */ /* @@ -436,7 +440,7 @@ int_div(mrb_state *mrb, mrb_value x) #ifdef MRB_NO_FLOAT mrb_raise(mrb, E_TYPE_ERROR, "non integer multiplication"); #else - return mrb_float_value(mrb, (mrb_float)a * mrb_to_flo(mrb, y)); + return mrb_float_value(mrb, mrb_num_div_flo(mrb, (mrb_float)a, mrb_to_flo(mrb, y))); #endif } } @@ -468,7 +472,7 @@ int_quo(mrb_state *mrb, mrb_value x) #ifdef MRB_NO_FLOAT mrb_raise(mrb, E_TYPE_ERROR, "non integer multiplication"); #else - return mrb_float_value(mrb, (mrb_float)a * mrb_to_flo(mrb, y)); + return mrb_float_value(mrb, mrb_num_div_flo(mrb, (mrb_float)a, mrb_to_flo(mrb, y))); #endif } } |
