Use `mrb_num_div_flo` for float division.

This function handles zero division properly. Also fixed bugs that multiply
numbers instead of division.
parent 98799aa6
......@@ -285,6 +285,8 @@ complex_div(mrb_state *mrb, mrb_value self)
return complex_new(mrb, F(ldexp)(zr.s, zr.x), F(ldexp)(zi.s, zi.x));
}
mrb_float mrb_num_div_flo(mrb_state*, mrb_float, mrb_float);
#ifndef MRB_USE_RATIONAL
mrb_int mrb_num_div_int(mrb_state *mrb, mrb_int x, mrb_int y);
......@@ -307,7 +309,7 @@ int_div(mrb_state *mrb, mrb_value x)
x = complex_new(mrb, (mrb_float)a, 0);
return mrb_funcall_id(mrb, x, MRB_OPSYM(div), 1, y);
default:
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)));
}
}
......@@ -327,7 +329,7 @@ int_quo(mrb_state *mrb, mrb_value x)
x = complex_new(mrb, (mrb_float)a, 0);
return mrb_funcall_id(mrb, x, MRB_OPSYM(div), 1, y);
default:
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
......
......@@ -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
}
}
......
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