diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-08-26 02:24:18 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-08-26 02:24:18 +0900 |
| commit | ecc77829ce76ad18995095bd39ffeae3e3663fac (patch) | |
| tree | caef850b5a733fe952c2a8a41752d01a591f0608 /src/numeric.c | |
| parent | b01b3c44728f66e0db1a9ab66fca7f6e8213f5e5 (diff) | |
| parent | bd6dc0da77470c2dfca7fbccf543cb94b17624af (diff) | |
| download | mruby-ecc77829ce76ad18995095bd39ffeae3e3663fac.tar.gz mruby-ecc77829ce76ad18995095bd39ffeae3e3663fac.zip | |
Merge pull request #2562 from cubicdaiya/issues/pow_flo
Fix and add test for Numeric#pow behavior.
Diffstat (limited to 'src/numeric.c')
| -rw-r--r-- | src/numeric.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/numeric.c b/src/numeric.c index 90ea6c965..3f211ca70 100644 --- a/src/numeric.c +++ b/src/numeric.c @@ -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); } |
