ruby-changes:51001
From: nobu <ko1@a...>
Date: Fri, 20 Apr 2018 09:23:06 +0900 (JST)
Subject: [ruby-changes:51001] nobu:r63208 (trunk): range.c: step in bignum
nobu 2018-04-20 09:23:01 +0900 (Fri, 20 Apr 2018) New Revision: 63208 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63208 Log: range.c: step in bignum * range.c (range_step): honor step in bignum addition. [Feature #12912] Modified files: trunk/range.c trunk/test/ruby/test_range.rb Index: range.c =================================================================== --- range.c (revision 63207) +++ range.c (revision 63208) @@ -408,7 +408,7 @@ range_step(int argc, VALUE *argv, VALUE https://github.com/ruby/ruby/blob/trunk/range.c#L408 } while (FIXABLE(i)); b = LONG2NUM(i); - for (;; b = rb_funcallv(b, id_succ, 0, 0)) + for (;; b = rb_big_plus(b, step)) rb_yield(b); } else if (FIXNUM_P(b) && FIXNUM_P(e) && FIXNUM_P(step)) { /* fixnums are special */ Index: test/ruby/test_range.rb =================================================================== --- test/ruby/test_range.rb (revision 63207) +++ test/ruby/test_range.rb (revision 63208) @@ -245,10 +245,13 @@ class TestRange < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_range.rb#L245 (2**32-1 .. ).step(2) {|x| a << x; break if a.size == 2 } assert_equal([4294967295, 4294967297], a) - a = [] max = RbConfig::LIMITS["FIXNUM_MAX"] + a = [] (max..).step {|x| a << x; break if a.size == 2 } assert_equal([max, max+1], a) + a = [] + (max..).step(max) {|x| a << x; break if a.size == 4 } + assert_equal([max, 2*max, 3*max, 4*max], a) o1 = Object.new o2 = Object.new -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/