1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

range.c: Range#size now returns Float::INFINITY if it is endless

Fixes [Bug #14699]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63715 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
mame 2018-06-22 02:58:39 +00:00
parent c19ecf05b4
commit 342619300c
2 changed files with 10 additions and 4 deletions

10
range.c
View file

@ -749,9 +749,15 @@ static VALUE
range_size(VALUE range)
{
VALUE b = RANGE_BEG(range), e = RANGE_END(range);
if (rb_obj_is_kind_of(b, rb_cNumeric) && rb_obj_is_kind_of(e, rb_cNumeric)) {
return ruby_num_interval_step_size(b, e, INT2FIX(1), EXCL(range));
if (rb_obj_is_kind_of(b, rb_cNumeric)) {
if (rb_obj_is_kind_of(e, rb_cNumeric)) {
return ruby_num_interval_step_size(b, e, INT2FIX(1), EXCL(range));
}
if (NIL_P(e)) {
return DBL2NUM(HUGE_VAL);
}
}
return Qnil;
}

View file

@ -582,8 +582,8 @@ class TestRange < Test::Unit::TestCase
assert_equal 42, (1..42).each.size
assert_nil ("a"..."z").size
assert_nil (1...).size
assert_nil (1.0...).size
assert_equal Float::INFINITY, (1...).size
assert_equal Float::INFINITY, (1.0...).size
assert_nil ("a"...).size
end