ruby-changes:54265
From: mrkn <ko1@a...>
Date: Fri, 21 Dec 2018 09:03:43 +0900 (JST)
Subject: [ruby-changes:54265] mrkn:r66474 (trunk): enumerator.c: Fix airth_seq_each for Rational
mrkn 2018-12-21 09:03:39 +0900 (Fri, 21 Dec 2018) New Revision: 66474 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66474 Log: enumerator.c: Fix airth_seq_each for Rational Fix the wrong uses of rb_int_ge in arith_seq_each. [ruby-core:90648] [Bug #15444] Modified files: trunk/enumerator.c trunk/test/ruby/test_arithmetic_sequence.rb Index: enumerator.c =================================================================== --- enumerator.c (revision 66473) +++ enumerator.c (revision 66474) @@ -3030,6 +3030,8 @@ arith_seq_hash(VALUE self) https://github.com/ruby/ruby/blob/trunk/enumerator.c#L3030 return LONG2FIX(hash); } +#define NUM_GE(x, y) RTEST(rb_num_coerce_relop((x), (y), idGE)) + struct arith_seq_gen { VALUE current; VALUE end; @@ -3083,13 +3085,13 @@ arith_seq_each(VALUE self) https://github.com/ruby/ruby/blob/trunk/enumerator.c#L3085 } if (rb_num_negative_int_p(s)) { - while (RTEST(rb_int_ge(c, last))) { + while (NUM_GE(c, last)) { rb_yield(c); c = rb_int_plus(c, s); } } else { - while (RTEST(rb_int_ge(last, c))) { + while (NUM_GE(last, c)) { rb_yield(c); c = rb_int_plus(c, s); } Index: test/ruby/test_arithmetic_sequence.rb =================================================================== --- test/ruby/test_arithmetic_sequence.rb (revision 66473) +++ test/ruby/test_arithmetic_sequence.rb (revision 66474) @@ -228,6 +228,12 @@ class TestArithmeticSequence < Test::Uni https://github.com/ruby/ruby/blob/trunk/test/ruby/test_arithmetic_sequence.rb#L228 assert_equal([10.0, 8.0, 6.0, 4.0, 2.0], (10.0..1.0).step(-2.0).to_a) end + def test_to_a_bug15444 + seq = ((1/10r)..(1/2r)).step(1/10r) + assert_num_equal_type([1/10r, 1/5r, 3/10r, 2/5r, 1/2r], seq.to_a, + '[ruby-core:90648] [Bug #15444]') + end + def test_slice seq = 1.step(10, 2) assert_equal([[1, 3, 5], [7, 9]], seq.each_slice(3).to_a) @@ -284,6 +290,14 @@ class TestArithmeticSequence < Test::Uni https://github.com/ruby/ruby/blob/trunk/test/ruby/test_arithmetic_sequence.rb#L290 [10, 8, 6, 4, 2].each do |i| assert_equal(i, seq.next) end + + seq = ((1/10r)..(1/2r)).step(0) + assert_equal(1/10r, seq.next) + end + + def test_next_bug15444 + seq = ((1/10r)..(1/2r)).step(1/10r) + assert_equal(1/10r, seq.next, '[ruby-core:90648] [Bug #15444]') end def test_next_rewind -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/