Commit a9b37bff authored by kkkkkt's avatar kkkkkt

refactor mrb_hash_shift, num_pow, flo_eq, flo_finite_p method

parent ad7085e4
......@@ -553,8 +553,7 @@ mrb_hash_shift(mrb_state *mrb, mrb_value hash)
mrb_value delKey, delVal;
mrb_hash_modify(mrb, hash);
if (h) {
if (kh_size(h) > 0) {
if (h && kh_size(h) > 0) {
for (k = kh_begin(h); k != kh_end(h); k++) {
if (!kh_exist(h,k)) continue;
......@@ -566,7 +565,6 @@ mrb_hash_shift(mrb_state *mrb, mrb_value hash)
return mrb_assoc_new(mrb, delKey, delVal);
}
}
}
if (MRB_RHASH_PROCDEFAULT_P(hash)) {
return mrb_funcall(mrb, RHASH_PROCDEFAULT(hash), "call", 2, hash, mrb_nil_value());
......
......@@ -54,13 +54,11 @@ static mrb_value
num_pow(mrb_state *mrb, mrb_value x)
{
mrb_value y;
mrb_bool both_int = FALSE;
mrb_float d;
mrb_get_args(mrb, "o", &y);
if (mrb_fixnum_p(x) && mrb_fixnum_p(y)) both_int = TRUE;
d = pow(mrb_to_flo(mrb, x), mrb_to_flo(mrb, y));
if (both_int && FIXABLE(d))
if (mrb_fixnum_p(x) && mrb_fixnum_p(y) && FIXABLE(d))
return mrb_fixnum_value((mrb_int)d);
return mrb_float_value(mrb, d);
}
......@@ -397,22 +395,16 @@ static mrb_value
flo_eq(mrb_state *mrb, mrb_value x)
{
mrb_value y;
volatile mrb_float a, b;
mrb_get_args(mrb, "o", &y);
switch (mrb_type(y)) {
case MRB_TT_FIXNUM:
b = (mrb_float)mrb_fixnum(y);
break;
return mrb_bool_value(mrb_float(x) == (mrb_float)mrb_fixnum(y));
case MRB_TT_FLOAT:
b = mrb_float(y);
break;
return mrb_bool_value(mrb_float(x) == (mrb_float)mrb_float(y));
default:
return mrb_false_value();
}
a = mrb_float(x);
return mrb_bool_value(a == b);
}
/* 15.2.8.3.18 */
......@@ -493,9 +485,7 @@ flo_infinite_p(mrb_state *mrb, mrb_value num)
static mrb_value
flo_finite_p(mrb_state *mrb, mrb_value num)
{
mrb_float value = mrb_float(num);
return mrb_bool_value(isfinite(value));
return mrb_bool_value(isfinite(mrb_float(num)));
}
/* 15.2.9.3.10 */
......
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