diff options
| author | Kouhei Yanagita <yanagi@shakenbu.org> | 2023-10-14 08:50:59 +0900 |
|---|---|---|
| committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2023-10-14 11:22:42 +0900 |
| commit | b28c1d2c5644c726bba60cd35ce9313da6e86a4f (patch) | |
| tree | 48902331bfab04912c91760e615c1b668f58dbae | |
| parent | 25072d2e878ea6093f04c67e90c5cef33d70080a (diff) | |
[Bug #19926] Fix Range#size for ranges with a Rational endpoint
| -rw-r--r-- | numeric.c | 2 | ||||
| -rw-r--r-- | test/ruby/test_range.rb | 4 |
2 files changed, 5 insertions, 1 deletions
@@ -2834,7 +2834,7 @@ ruby_num_interval_step_size(VALUE from, VALUE to, VALUE step, int excl) } if (RTEST(rb_funcall(from, cmp, 1, to))) return INT2FIX(0); result = rb_funcall(rb_funcall(to, '-', 1, from), id_div, 1, step); - if (!excl || RTEST(rb_funcall(rb_funcall(from, '+', 1, rb_funcall(result, '*', 1, step)), cmp, 1, to))) { + if (!excl || RTEST(rb_funcall(to, cmp, 1, rb_funcall(from, '+', 1, rb_funcall(result, '*', 1, step))))) { result = rb_funcall(result, '+', 1, INT2FIX(1)); } return result; diff --git a/test/ruby/test_range.rb b/test/ruby/test_range.rb index 8228b6cfbe..4990b78179 100644 --- a/test/ruby/test_range.rb +++ b/test/ruby/test_range.rb @@ -977,6 +977,10 @@ class TestRange < Test::Unit::TestCase assert_equal 41, (1...42).size assert_equal 6, (1...6.3).size assert_equal 5, (1.1...6).size + assert_equal 3, (1..3r).size + assert_equal 2, (1...3r).size + assert_equal 3, (1..3.1r).size + assert_equal 3, (1...3.1r).size assert_equal 42, (1..42).each.size assert_nil ("a"..."z").size assert_nil ("a"...).size |
