numeric.c: merge `mrb_as_float` implementation to `mrb_ensure_float_type`.

Since they are basically duplicated functionality. `mrb_as_float` is now
a macro defined using `mrb_ensure_float_type`; #5620
parent 566a8d3f
...@@ -1270,6 +1270,7 @@ MRB_API mrb_bool mrb_obj_equal(mrb_state *mrb, mrb_value a, mrb_value b); ...@@ -1270,6 +1270,7 @@ MRB_API mrb_bool mrb_obj_equal(mrb_state *mrb, mrb_value a, mrb_value b);
MRB_API mrb_bool mrb_equal(mrb_state *mrb, mrb_value obj1, mrb_value obj2); MRB_API mrb_bool mrb_equal(mrb_state *mrb, mrb_value obj1, mrb_value obj2);
#ifndef MRB_NO_FLOAT #ifndef MRB_NO_FLOAT
MRB_API mrb_value mrb_ensure_float_type(mrb_state *mrb, mrb_value val); MRB_API mrb_value mrb_ensure_float_type(mrb_state *mrb, mrb_value val);
#define mrb_as_float(mrb, x) mrb_float(mrb_ensure_float_type(mrb, x))
/* obsolete: use mrb_ensure_float_type() instead */ /* obsolete: use mrb_ensure_float_type() instead */
#define mrb_to_float(mrb, val) mrb_ensure_float_type(mrb, val) #define mrb_to_float(mrb, val) mrb_ensure_float_type(mrb, val)
#endif #endif
......
...@@ -160,7 +160,6 @@ mrb_int_mul_overflow(mrb_int a, mrb_int b, mrb_int *c) ...@@ -160,7 +160,6 @@ mrb_int_mul_overflow(mrb_int a, mrb_int b, mrb_int *c)
# endif /* MRB_USE_FLOAT32 */ # endif /* MRB_USE_FLOAT32 */
MRB_API mrb_value mrb_float_to_integer(mrb_state *mrb, mrb_value val); MRB_API mrb_value mrb_float_to_integer(mrb_state *mrb, mrb_value val);
MRB_API mrb_float mrb_as_float(mrb_state *mrb, mrb_value x);
/* internal functions */ /* internal functions */
mrb_float mrb_div_float(mrb_float x, mrb_float y); mrb_float mrb_div_float(mrb_float x, mrb_float y);
......
...@@ -20,27 +20,6 @@ ...@@ -20,27 +20,6 @@
#endif #endif
#endif #endif
#ifndef MRB_NO_FLOAT
MRB_API mrb_float
mrb_as_float(mrb_state *mrb, mrb_value val)
{
switch (mrb_type(val)) {
case MRB_TT_INTEGER:
return (mrb_float)mrb_integer(val);
case MRB_TT_FLOAT:
break;
case MRB_TT_RATIONAL:
case MRB_TT_COMPLEX:
val = mrb_type_convert(mrb, val, MRB_TT_FLOAT, MRB_SYM(to_f));
break;
default:
mrb_raise(mrb, E_TYPE_ERROR, "non float value");
break;
}
return mrb_float(val);
}
#endif
static void static void
int_overflow(mrb_state *mrb, const char *reason) int_overflow(mrb_state *mrb, const char *reason)
{ {
......
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