Skip to content

Commit b28c1d2

Browse files
kyanaginobu
authored andcommitted
[Bug #19926] Fix Range#size for ranges with a Rational endpoint
1 parent 25072d2 commit b28c1d2

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

numeric.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2834,7 +2834,7 @@ ruby_num_interval_step_size(VALUE from, VALUE to, VALUE step, int excl)
28342834
}
28352835
if (RTEST(rb_funcall(from, cmp, 1, to))) return INT2FIX(0);
28362836
result = rb_funcall(rb_funcall(to, '-', 1, from), id_div, 1, step);
2837-
if (!excl || RTEST(rb_funcall(rb_funcall(from, '+', 1, rb_funcall(result, '*', 1, step)), cmp, 1, to))) {
2837+
if (!excl || RTEST(rb_funcall(to, cmp, 1, rb_funcall(from, '+', 1, rb_funcall(result, '*', 1, step))))) {
28382838
result = rb_funcall(result, '+', 1, INT2FIX(1));
28392839
}
28402840
return result;

test/ruby/test_range.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,10 @@ def test_size
977977
assert_equal 41, (1...42).size
978978
assert_equal 6, (1...6.3).size
979979
assert_equal 5, (1.1...6).size
980+
assert_equal 3, (1..3r).size
981+
assert_equal 2, (1...3r).size
982+
assert_equal 3, (1..3.1r).size
983+
assert_equal 3, (1...3.1r).size
980984
assert_equal 42, (1..42).each.size
981985
assert_nil ("a"..."z").size
982986
assert_nil ("a"...).size

0 commit comments

Comments
 (0)