summaryrefslogtreecommitdiff
path: root/bignum.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-10-02 16:42:21 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-10-02 16:42:21 +0000
commit603f95a0ed37d90854f80393881fb38ab29128a7 (patch)
tree2f76d289cf541c53cb29dff917569d0846a12613 /bignum.c
parent25ea4dc6230f3141dcb3b9d04c9124bc07146bca (diff)
downloadbundler-603f95a0ed37d90854f80393881fb38ab29128a7.tar.gz
Fix Rational of Float
[ruby-core:89239] [Bug #15189] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64897 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'bignum.c')
-rw-r--r--bignum.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/bignum.c b/bignum.c
index ee481e1bd7..e53b2bd2c1 100644
--- a/bignum.c
+++ b/bignum.c
@@ -6207,6 +6207,7 @@ rb_big_pow(VALUE x, VALUE y)
again:
if (y == INT2FIX(0)) return INT2FIX(1);
+ if (y == INT2FIX(1)) return x;
if (RB_FLOAT_TYPE_P(y)) {
d = RFLOAT_VALUE(y);
if ((BIGNUM_NEGATIVE_P(x) && !BIGZEROP(x))) {
@@ -6223,8 +6224,13 @@ rb_big_pow(VALUE x, VALUE y)
else if (FIXNUM_P(y)) {
yy = FIX2LONG(y);
- if (yy < 0)
- return rb_rational_raw(INT2FIX(1), rb_big_pow(x, INT2NUM(-yy)));
+ if (yy < 0) {
+ x = rb_big_pow(x, INT2NUM(-yy));
+ if (RB_INTEGER_TYPE_P(x))
+ return rb_rational_raw(INT2FIX(1), x);
+ else
+ return DBL2NUM(1.0 / NUM2DBL(x));
+ }
else {
VALUE z = 0;
SIGNED_VALUE mask;