[前][次][番号順一覧][スレッド一覧]

ruby-changes:19247

From: usa <ko1@a...>
Date: Fri, 15 Apr 2011 17:04:07 +0900 (JST)
Subject: [ruby-changes:19247] Ruby:r31286 (trunk): * numeric.c (ruby_float_step): wrong loop condition.

usa	2011-04-14 23:50:46 +0900 (Thu, 14 Apr 2011)

  New Revision: 31286

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=31286

  Log:
    * 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.

  Modified files:
    trunk/ChangeLog
    trunk/numeric.c
    trunk/test/ruby/test_range.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 31285)
+++ ChangeLog	(revision 31286)
@@ -1,3 +1,11 @@
+Thu Apr 14 23:43:43 2011  NAKAMURA Usaku  <usa@r...>
+
+	* 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 Apr 14 22:48:12 2011  Nobuyoshi Nakada  <nobu@r...>
 
 	* lib/test/unit.rb (Test::Unit::Options#setup_options): set possible
Index: numeric.c
===================================================================
--- numeric.c	(revision 31285)
+++ numeric.c	(revision 31286)
@@ -1634,7 +1634,7 @@
 	else {
 	    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(DBL2NUM(i*unit+beg));
 	    }
Index: test/ruby/test_range.rb
===================================================================
--- test/ruby/test_range.rb	(revision 31285)
+++ test/ruby/test_range.rb	(revision 31286)
@@ -182,6 +182,15 @@
     assert_nothing_raised("[ruby-dev:34558]") { (0..2).step(o) {|x| } }
   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
+
   def test_each
     a = []
     (0..10).each {|x| a << x }

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]