diff options
-rw-r--r-- | rational.c | 4 | ||||
-rw-r--r-- | test/ruby/test_rational.rb | 2 |
2 files changed, 6 insertions, 0 deletions
diff --git a/rational.c b/rational.c index e779505fd0..4bdc695dc1 100644 --- a/rational.c +++ b/rational.c @@ -1046,6 +1046,10 @@ nurat_expt(VALUE self, VALUE other) if (RB_FLOAT_TYPE_P(den)) return DBL2NUM(NAN); return num; } + if (RB_FLOAT_TYPE_P(den)) { /* infinity due to overflow */ + num = ZERO; + den = ONE; + } return f_rational_new2(CLASS_OF(self), num, den); } } diff --git a/test/ruby/test_rational.rb b/test/ruby/test_rational.rb index c1e7d824d1..e0cb8db99e 100644 --- a/test/ruby/test_rational.rb +++ b/test/ruby/test_rational.rb @@ -959,6 +959,8 @@ class Rational_Test < Test::Unit::TestCase bug = '[ruby-core:79686] [Bug #13242]: Infinity due to overflow' x = EnvUtil.suppress_warning {4r**40000000} assert_predicate x, :infinite?, bug + x = EnvUtil.suppress_warning {(1/4r)**40000000} + assert_equal 0, x, bug end def test_positive_p |