[前][次][番号順一覧][スレッド一覧]

ruby-changes:45838

From: naruse <ko1@a...>
Date: Sun, 12 Mar 2017 23:18:07 +0900 (JST)
Subject: [ruby-changes:45838] naruse:r57911 (ruby_2_4): merge revision(s) 57688, 57689: [Backport #13242]

naruse	2017-03-12 23:18:02 +0900 (Sun, 12 Mar 2017)

  New Revision: 57911

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57911

  Log:
    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]:

  Modified directories:
    branches/ruby_2_4/
  Modified files:
    branches/ruby_2_4/numeric.c
    branches/ruby_2_4/rational.c
    branches/ruby_2_4/test/ruby/test_rational.rb
    branches/ruby_2_4/version.h
Index: ruby_2_4/rational.c
===================================================================
--- ruby_2_4/rational.c	(revision 57910)
+++ ruby_2_4/rational.c	(revision 57911)
@@ -1039,6 +1039,14 @@ nurat_expt(VALUE self, VALUE other) https://github.com/ruby/ruby/blob/trunk/ruby_2_4/rational.c#L1039
 		num = ONE;
 		den = ONE;
 	    }
+	    if (RB_FLOAT_TYPE_P(num)) { /* infinity due to overflow */
+		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);
 	}
     }
Index: ruby_2_4/numeric.c
===================================================================
--- ruby_2_4/numeric.c	(revision 57910)
+++ ruby_2_4/numeric.c	(revision 57911)
@@ -3904,6 +3904,8 @@ int_pow(long x, unsigned long y) https://github.com/ruby/ruby/blob/trunk/ruby_2_4/numeric.c#L3904
 		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;
 	    }
Index: ruby_2_4/version.h
===================================================================
--- ruby_2_4/version.h	(revision 57910)
+++ ruby_2_4/version.h	(revision 57911)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_4/version.h#L1
 #define RUBY_VERSION "2.4.0"
 #define RUBY_RELEASE_DATE "2017-03-12"
-#define RUBY_PATCHLEVEL 67
+#define RUBY_PATCHLEVEL 68
 
 #define RUBY_RELEASE_YEAR 2017
 #define RUBY_RELEASE_MONTH 3
Index: ruby_2_4/test/ruby/test_rational.rb
===================================================================
--- ruby_2_4/test/ruby/test_rational.rb	(revision 57910)
+++ ruby_2_4/test/ruby/test_rational.rb	(revision 57911)
@@ -955,6 +955,14 @@ class Rational_Test < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/ruby_2_4/test/ruby/test_rational.rb#L955
     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
+    x = EnvUtil.suppress_warning {(1/4r)**40000000}
+    assert_equal 0, x, bug
+  end
+
   def test_positive_p
     assert_predicate(1/2r, :positive?)
     assert_not_predicate(-1/2r, :positive?)

Property changes on: ruby_2_4
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r57688-57689


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]