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
This commit is contained in:
Yukihiro "Matz" Matsumoto
2021-12-31 10:26:58 +09:00
parent eea418bcce
commit 7f40b645d2
+5 -5
View File
@@ -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);
}