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

ruby-changes:34145

From: nagachika <ko1@a...>
Date: Thu, 29 May 2014 21:07:43 +0900 (JST)
Subject: [ruby-changes:34145] nagachika:r46226 (ruby_2_1): merge revision(s) r45187, r45205, r45206, r45212, r45213: [Backport #9570]

nagachika	2014-05-29 21:07:33 +0900 (Thu, 29 May 2014)

  New Revision: 46226

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

  Log:
    merge revision(s) r45187,r45205,r45206,r45212,r45213: [Backport #9570]
    
    * numeric.c (ruby_num_interval_step_size): check signs and get rid
      of implementation dependent behavior of negative division.
      [ruby-core:61106] [Bug #9570]

  Modified directories:
    branches/ruby_2_1/
  Modified files:
    branches/ruby_2_1/ChangeLog
    branches/ruby_2_1/numeric.c
    branches/ruby_2_1/test/ruby/test_numeric.rb
    branches/ruby_2_1/version.h
Index: ruby_2_1/ChangeLog
===================================================================
--- ruby_2_1/ChangeLog	(revision 46225)
+++ ruby_2_1/ChangeLog	(revision 46226)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ChangeLog#L1
+Thu May 29 20:57:59 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* numeric.c (ruby_num_interval_step_size): check signs and get rid
+	  of implementation dependent behavior of negative division.
+	  [ruby-core:61106] [Bug #9570]
+
 Wed May 28 23:47:22 2014  Nobuyoshi Nakada  <nobu@r...>
 
 	* configure.in (rb_cv_func___builtin_unreachable): try with an
Index: ruby_2_1/numeric.c
===================================================================
--- ruby_2_1/numeric.c	(revision 46225)
+++ ruby_2_1/numeric.c	(revision 46226)
@@ -1799,21 +1799,29 @@ VALUE https://github.com/ruby/ruby/blob/trunk/ruby_2_1/numeric.c#L1799
 ruby_num_interval_step_size(VALUE from, VALUE to, VALUE step, int excl)
 {
     if (FIXNUM_P(from) && FIXNUM_P(to) && FIXNUM_P(step)) {
-	long delta, diff, result;
+	long delta, diff;
 
 	diff = FIX2LONG(step);
+	if (!diff) rb_num_zerodiv();
 	delta = FIX2LONG(to) - FIX2LONG(from);
+	if (diff < 0) {
+	    diff = -diff;
+	    delta = -delta;
+	}
 	if (excl) {
-	    delta += (diff > 0 ? -1 : +1);
+	    delta--;
+	}
+	if (delta < 0) {
+	    return INT2FIX(0);
 	}
-	result = delta / diff;
-	return LONG2FIX(result >= 0 ? result + 1 : 0);
+	return ULONG2NUM(delta / diff + 1UL);
     }
     else if (RB_TYPE_P(from, T_FLOAT) || RB_TYPE_P(to, T_FLOAT) || RB_TYPE_P(step, T_FLOAT)) {
 	double n = ruby_float_step_size(NUM2DBL(from), NUM2DBL(to), NUM2DBL(step), excl);
 
 	if (isinf(n)) return DBL2NUM(n);
-	return LONG2FIX(n);
+	if (POSFIXABLE(n)) return LONG2FIX(n);
+	return rb_dbl2big(n);
     }
     else {
 	VALUE result;
Index: ruby_2_1/version.h
===================================================================
--- ruby_2_1/version.h	(revision 46225)
+++ ruby_2_1/version.h	(revision 46226)
@@ -1,10 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/version.h#L1
 #define RUBY_VERSION "2.1.2"
-#define RUBY_RELEASE_DATE "2014-05-28"
-#define RUBY_PATCHLEVEL 115
+#define RUBY_RELEASE_DATE "2014-05-29"
+#define RUBY_PATCHLEVEL 116
 
 #define RUBY_RELEASE_YEAR 2014
 #define RUBY_RELEASE_MONTH 5
-#define RUBY_RELEASE_DAY 28
+#define RUBY_RELEASE_DAY 29
 
 #include "ruby/version.h"
 
Index: ruby_2_1/test/ruby/test_numeric.rb
===================================================================
--- ruby_2_1/test/ruby/test_numeric.rb	(revision 46225)
+++ ruby_2_1/test/ruby/test_numeric.rb	(revision 46226)
@@ -223,6 +223,8 @@ class TestNumeric < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_numeric.rb#L223
   end
 
   def test_step
+    i, bignum = 32, 1 << 30
+    bignum <<= (i <<= 1) - 32 until bignum.is_a?(Bignum)
     assert_raise(ArgumentError) { 1.step(10, 1, 0) { } }
     assert_raise(ArgumentError) { 1.step(10, 1, 0).size }
     assert_raise(ArgumentError) { 1.step(10, 0) { } }
@@ -238,6 +240,17 @@ class TestNumeric < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_numeric.rb#L240
     assert_nothing_raised { 1.step(by: nil) }
     assert_nothing_raised { 1.step(by: nil).size }
 
+    assert_equal(bignum*2+1, (-bignum).step(bignum, 1).size)
+    assert_equal(bignum*2, (-bignum).step(bignum-1, 1).size)
+
+    assert_equal(10+1, (0.0).step(10.0, 1.0).size)
+
+    i, bigflo = 1, bignum.to_f
+    i <<= 1 until (bigflo - i).to_i < bignum
+    bigflo -= i >> 1
+    assert_equal(bigflo.to_i, (0.0).step(bigflo-1.0, 1.0).size)
+    assert_operator((0.0).step(bignum.to_f, 1.0).size, :>=, bignum) # may loose precision
+
     assert_step [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 10]
     assert_step [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, to: 10]
     assert_step [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, to: 10, by: nil]
@@ -248,15 +261,17 @@ class TestNumeric < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_numeric.rb#L261
     assert_step [10, 8, 6, 4, 2], [10, to: 1, by: -2]
     assert_step [1.0, 3.0, 5.0, 7.0, 9.0], [1.0, 10.0, 2.0]
     assert_step [1.0, 3.0, 5.0, 7.0, 9.0], [1.0, to: 10.0, by: 2.0]
-    assert_step [1], [1, 10, 2**32]
-    assert_step [1], [1, to: 10, by: 2**32]
+    assert_step [1], [1, 10, bignum]
+    assert_step [1], [1, to: 10, by: bignum]
 
+    assert_step [], [2, 1, 3]
+    assert_step [], [-2, -1, -3]
     assert_step [3, 3, 3, 3], [3, by: 0], inf: true
-    assert_step [10], [10, 1, -(2**32)]
+    assert_step [10], [10, 1, -bignum]
 
     assert_step [], [1, 0, Float::INFINITY]
     assert_step [], [0, 1, -Float::INFINITY]
-    assert_step [10], [10, to: 1, by: -(2**32)]
+    assert_step [10], [10, to: 1, by: -bignum]
 
     assert_step [10, 11, 12, 13], [10], inf: true
     assert_step [10, 9, 8, 7], [10, by: -1], inf: true

Property changes on: ruby_2_1
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r45187,45205-45206,45212-45213


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

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