summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-03-25 18:16:16 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-03-25 18:16:16 +0000
commitf84d286415328e4dfd64968d146d916ce60791aa (patch)
tree78ab593b57f2915c707d77f19e5f3f948e88a1c6
parentd41018464386c1ce686a65af03fb711a9af1baa1 (diff)
merge revision(s) 57688,57689: [Backport #13242]
rational.c: infinity in power * rational.c (nurat_expt): return Infinity due to overflow. [ruby-core:79686] [Bug #13242]: rational.c: infinity in power * rational.c (nurat_expt): return 0 due to overflow. [ruby-core:79686] [Bug #13242]: git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@58117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--numeric.c2
-rw-r--r--rational.c4
-rw-r--r--test/ruby/test_rational.rb6
-rw-r--r--version.h2
4 files changed, 13 insertions, 1 deletions
diff --git a/numeric.c b/numeric.c
index 2cf2c05292..6f845c9d54 100644
--- a/numeric.c
+++ b/numeric.c
@@ -3158,6 +3158,8 @@ int_pow(long x, unsigned long y)
VALUE v;
bignum:
v = rb_big_pow(rb_int2big(x), LONG2NUM(y));
+ if (RB_FLOAT_TYPE_P(v)) /* infinity due to overflow */
+ return v;
if (z != 1) v = rb_big_mul(rb_int2big(neg ? -z : z), v);
return v;
}
diff --git a/rational.c b/rational.c
index 3e5dea3349..97d9b35a16 100644
--- a/rational.c
+++ b/rational.c
@@ -1043,6 +1043,10 @@ nurat_expt(VALUE self, VALUE other)
den = ONE;
break;
}
+ if (RB_FLOAT_TYPE_P(num)) { /* infinity due to overflow */
+ if (RB_FLOAT_TYPE_P(den)) return DBL2NUM(NAN);
+ return num;
+ }
return f_rational_new2(CLASS_OF(self), num, den);
}
}
diff --git a/test/ruby/test_rational.rb b/test/ruby/test_rational.rb
index 44f7280071..76850053e6 100644
--- a/test/ruby/test_rational.rb
+++ b/test/ruby/test_rational.rb
@@ -931,6 +931,12 @@ class Rational_Test < Test::Unit::TestCase
assert_raise(ZeroDivisionError, bug5713) { Rational(0, 1) ** Rational(-2,3) }
end
+ def test_power_overflow
+ bug = '[ruby-core:79686] [Bug #13242]: Infinity due to overflow'
+ x = EnvUtil.suppress_warning {4r**40000000}
+ assert_predicate x, :infinite?, bug
+ end
+
def test_known_bug
end
diff --git a/version.h b/version.h
index 92210031ee..5612f4cc74 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@
#define RUBY_VERSION "2.2.7"
#define RUBY_RELEASE_DATE "2017-03-26"
-#define RUBY_PATCHLEVEL 449
+#define RUBY_PATCHLEVEL 450
#define RUBY_RELEASE_YEAR 2017
#define RUBY_RELEASE_MONTH 3