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

ruby-changes:46046

From: usa <ko1@a...>
Date: Sun, 26 Mar 2017 03:16:23 +0900 (JST)
Subject: [ruby-changes:46046] usa:r58117 (ruby_2_2): merge revision(s) 57688, 57689: [Backport #13242]

usa	2017-03-26 03:16:16 +0900 (Sun, 26 Mar 2017)

  New Revision: 58117

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

  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_2/
  Modified files:
    branches/ruby_2_2/numeric.c
    branches/ruby_2_2/rational.c
    branches/ruby_2_2/test/ruby/test_rational.rb
    branches/ruby_2_2/version.h
Index: ruby_2_2/numeric.c
===================================================================
--- ruby_2_2/numeric.c	(revision 58116)
+++ ruby_2_2/numeric.c	(revision 58117)
@@ -3158,6 +3158,8 @@ int_pow(long x, unsigned long y) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/numeric.c#L3158
 		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_2/version.h
===================================================================
--- ruby_2_2/version.h	(revision 58116)
+++ ruby_2_2/version.h	(revision 58117)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/version.h#L1
 #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
Index: ruby_2_2/test/ruby/test_rational.rb
===================================================================
--- ruby_2_2/test/ruby/test_rational.rb	(revision 58116)
+++ ruby_2_2/test/ruby/test_rational.rb	(revision 58117)
@@ -931,6 +931,12 @@ class Rational_Test < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/ruby_2_2/test/ruby/test_rational.rb#L931
     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
 
Index: ruby_2_2/rational.c
===================================================================
--- ruby_2_2/rational.c	(revision 58116)
+++ ruby_2_2/rational.c	(revision 58117)
@@ -1043,6 +1043,10 @@ nurat_expt(VALUE self, VALUE other) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/rational.c#L1043
 		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);
 	}
     }

Property changes on: ruby_2_2
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r57688


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

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