mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66474 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
ccdba542d3
commit
09b3d38c72
2 changed files with 18 additions and 2 deletions
|
@ -3030,6 +3030,8 @@ arith_seq_hash(VALUE self)
|
|||
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)
|
|||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -228,6 +228,12 @@ class TestArithmeticSequence < Test::Unit::TestCase
|
|||
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::Unit::TestCase
|
|||
[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
|
||||
|
|
Loading…
Reference in a new issue