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

ruby-changes:33171

From: nagachika <ko1@a...>
Date: Mon, 3 Mar 2014 01:10:54 +0900 (JST)
Subject: [ruby-changes:33171] nagachika:r45250 (ruby_2_0_0): merge revision(s) r45187, r45205, r45212, r45213: [Backport #9570]

nagachika	2014-03-03 01:10:47 +0900 (Mon, 03 Mar 2014)

  New Revision: 45250

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

  Log:
    merge revision(s) r45187,r45205,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_0_0/
  Modified files:
    branches/ruby_2_0_0/ChangeLog
    branches/ruby_2_0_0/numeric.c
    branches/ruby_2_0_0/test/ruby/test_numeric.rb
    branches/ruby_2_0_0/version.h
Index: ruby_2_0_0/ChangeLog
===================================================================
--- ruby_2_0_0/ChangeLog	(revision 45249)
+++ ruby_2_0_0/ChangeLog	(revision 45250)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ChangeLog#L1
+Mon Mar  3 01:00:00 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]
+
 Mon Mar  3 00:43:33 2014  CHIKANAGA Tomoyuki  <nagachika@r...>
 
 	(merged partially from r42781)
Index: ruby_2_0_0/numeric.c
===================================================================
--- ruby_2_0_0/numeric.c	(revision 45249)
+++ ruby_2_0_0/numeric.c	(revision 45250)
@@ -1816,21 +1816,29 @@ VALUE https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/numeric.c#L1816
 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_0_0/version.h
===================================================================
--- ruby_2_0_0/version.h	(revision 45249)
+++ ruby_2_0_0/version.h	(revision 45250)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/version.h#L1
 #define RUBY_VERSION "2.0.0"
 #define RUBY_RELEASE_DATE "2014-03-03"
-#define RUBY_PATCHLEVEL 453
+#define RUBY_PATCHLEVEL 454
 
 #define RUBY_RELEASE_YEAR 2014
 #define RUBY_RELEASE_MONTH 3
Index: ruby_2_0_0/test/ruby/test_numeric.rb
===================================================================
--- ruby_2_0_0/test/ruby/test_numeric.rb	(revision 45249)
+++ ruby_2_0_0/test/ruby/test_numeric.rb	(revision 45250)
@@ -243,17 +243,32 @@ class TestNumeric < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_numeric.rb#L243
   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, 0) { } }
 
+    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, 3, 5, 7, 9], [1, 10, 2]
 
     assert_step [10, 8, 6, 4, 2], [10, 1, -2]
     assert_step [1.0, 3.0, 5.0, 7.0, 9.0], [1.0, 10.0, 2.0]
-    assert_step [1], [1, 10, 2**32]
+    assert_step [1], [1, 10, bignum]
 
-    assert_step [10], [10, 1, -(2**32)]
+    assert_step [], [2, 1, 3]
+    assert_step [], [-2, -1, -3]
+    assert_step [10], [10, 1, -(bignum)]
 
     assert_step [], [1, 0, Float::INFINITY]
     assert_step [], [0, 1, -Float::INFINITY]

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


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

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