summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-04-18 01:12:36 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-04-18 01:12:36 +0000
commit40397db9da2481cd48aeceab027269d66a8430bd (patch)
treedaac1b07b757074325c7bc5ef9b522a768fcc798
parent03373b29e3f452a87427f20b595fe66afefe1b9d (diff)
backported r31286 from trunk
* numeric.c (ruby_float_step): wrong loop condition. fixes [ruby-core:35753], reported by Joey Zhou. * test/ruby/test_range.rb (TestRange#test_step_ruby_core_35753): test above change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@31302 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog10
-rw-r--r--numeric.c2
-rw-r--r--test/ruby/test_range.rb9
3 files changed, 20 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 4e126df614..b3f4480f62 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+Mon Apr 18 10:04:41 2011 NAKAMURA Usaku <[email protected]>
+
+ backported r31286 from trunk
+
+ * numeric.c (ruby_float_step): wrong loop condition.
+ fixes [ruby-core:35753], reported by Joey Zhou.
+
+ * test/ruby/test_range.rb (TestRange#test_step_ruby_core_35753):
+ test above change.
+
Thu Mar 3 17:10:49 2011 Akinori MUSHA <[email protected]>
* array.c (rb_ary_collect), enum.c (enum_collect): Add
diff --git a/numeric.c b/numeric.c
index 800d723df0..28704db389 100644
--- a/numeric.c
+++ b/numeric.c
@@ -1445,7 +1445,7 @@ ruby_float_step(from, to, step, excl)
if (err>0.5) err=0.5;
n = floor(n + err);
- if (!excl) n++;
+ if (!excl || ((long)n)*unit+beg < end) n++;
for (i=0; i<n; i++) {
rb_yield(rb_float_new(i*unit+beg));
}
diff --git a/test/ruby/test_range.rb b/test/ruby/test_range.rb
index 455175087d..14f59e2ff5 100644
--- a/test/ruby/test_range.rb
+++ b/test/ruby/test_range.rb
@@ -14,4 +14,13 @@ class TestRange < Test::Unit::TestCase
r = (arr.shift)..(arr.shift)
assert_equal(1..2, r, "[ruby-dev:26383]")
end
+
+ def test_step_ruby_core_35753
+ assert_equal(6, (1...6.3).step.to_a.size)
+ assert_equal(5, (1.1...6).step.to_a.size)
+ assert_equal(5, (1...6).step(1.1).to_a.size)
+ assert_equal(3, (1.0...6.3).step(1.8).to_a.size)
+ assert_equal(3, (1.0...6.4).step(1.8).to_a.size)
+ assert_equal(4, (1.0...6.5).step(1.8).to_a.size)
+ end
end