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

ruby-changes:45989

From: nagachika <ko1@a...>
Date: Wed, 22 Mar 2017 23:13:44 +0900 (JST)
Subject: [ruby-changes:45989] nagachika:r58060 (ruby_2_3): merge revision(s) 57688, 57689: [Backport #13242]

nagachika	2017-03-22 23:13:40 +0900 (Wed, 22 Mar 2017)

  New Revision: 58060

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

  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_3/
  Modified files:
    branches/ruby_2_3/numeric.c
    branches/ruby_2_3/rational.c
    branches/ruby_2_3/test/ruby/test_rational.rb
    branches/ruby_2_3/version.h
Index: ruby_2_3/numeric.c
===================================================================
--- ruby_2_3/numeric.c	(revision 58059)
+++ ruby_2_3/numeric.c	(revision 58060)
@@ -3243,6 +3243,8 @@ int_pow(long x, unsigned long y) https://github.com/ruby/ruby/blob/trunk/ruby_2_3/numeric.c#L3243
 		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_3/rational.c
===================================================================
--- ruby_2_3/rational.c	(revision 58059)
+++ ruby_2_3/rational.c	(revision 58060)
@@ -1038,6 +1038,14 @@ nurat_expt(VALUE self, VALUE other) https://github.com/ruby/ruby/blob/trunk/ruby_2_3/rational.c#L1038
 		den = ONE;
 		break;
 	    }
+	    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_3/version.h
===================================================================
--- ruby_2_3/version.h	(revision 58059)
+++ ruby_2_3/version.h	(revision 58060)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/version.h#L1
 #define RUBY_VERSION "2.3.3"
 #define RUBY_RELEASE_DATE "2017-03-22"
-#define RUBY_PATCHLEVEL 257
+#define RUBY_PATCHLEVEL 258
 
 #define RUBY_RELEASE_YEAR 2017
 #define RUBY_RELEASE_MONTH 3
Index: ruby_2_3/test/ruby/test_rational.rb
===================================================================
--- ruby_2_3/test/ruby/test_rational.rb	(revision 58059)
+++ ruby_2_3/test/ruby/test_rational.rb	(revision 58060)
@@ -927,6 +927,14 @@ class Rational_Test < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/ruby/test_rational.rb#L927
     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_3
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r57688-57689


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

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