Commit 0e9f98c4 authored by Tatsuhiko Kubo's avatar Tatsuhiko Kubo

Fix Numeric#pow behavior.

 * Before

2 ** -1 #=> 0

 * After

2 ** -1 #=> 0.5
parent b01b3c44
......@@ -54,11 +54,12 @@ static mrb_value
num_pow(mrb_state *mrb, mrb_value x)
{
mrb_value y;
mrb_float d;
mrb_float d, yv;
mrb_get_args(mrb, "o", &y);
d = pow(mrb_to_flo(mrb, x), mrb_to_flo(mrb, y));
if (mrb_fixnum_p(x) && mrb_fixnum_p(y) && FIXABLE(d))
yv = mrb_to_flo(mrb, y);
d = pow(mrb_to_flo(mrb, x), yv);
if (mrb_fixnum_p(x) && mrb_fixnum_p(y) && FIXABLE(d) && yv > 0)
return mrb_fixnum_value((mrb_int)d);
return mrb_float_value(mrb, d);
}
......
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