numeric.c: `mrb_as_float` should not call `to_f` for generic objects.

It should only call `to_f` for Rational and Complex numbers.
Ref #5540 #5613 #5620
parent eea418bc
......@@ -29,13 +29,13 @@ mrb_as_float(mrb_state *mrb, mrb_value val)
return (mrb_float)mrb_integer(val);
case MRB_TT_FLOAT:
break;
case MRB_TT_STRING:
case MRB_TT_FALSE:
case MRB_TT_TRUE:
mrb_raise(mrb, E_TYPE_ERROR, "non float value");
default:
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);
}
......
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