numeric.c (cmpnum): fix a bug in float-bigint comparison

Should have used bigint to float conversion.
This commit is contained in:
Yukihiro "Matz" Matsumoto
2024-06-17 08:52:22 +09:00
parent 0f2d12a005
commit b8396aec33
+9 -9
View File
@@ -1881,15 +1881,6 @@ int_to_s(mrb_state *mrb, mrb_value self)
static mrb_int
cmpnum(mrb_state *mrb, mrb_value v1, mrb_value v2)
{
#ifdef MRB_USE_BIGINT
if (mrb_bigint_p(v1)) {
return mrb_bint_cmp(mrb, v1, v2);
}
if (mrb_bigint_p(v2)) {
return mrb_bint_cmp(mrb, mrb_bint_new_int(mrb, mrb_integer(v1)), v2);
}
#endif
#ifdef MRB_NO_FLOAT
mrb_int x, y;
#else
@@ -1904,8 +1895,17 @@ cmpnum(mrb_state *mrb, mrb_value v1, mrb_value v2)
switch (mrb_type(v2)) {
case MRB_TT_INTEGER:
#ifdef MRB_NO_FLOAT
#ifdef MRB_USE_BIGINT
return -2;
#endif
y = mrb_integer(v2);
#else
#ifdef MRB_USE_BIGINT
if (mrb_bigint_p(v2)) {
y = mrb_bint_as_float(mrb, v2);
break;
}
#endif
y = (mrb_float)mrb_integer(v2);
#endif
break;