From: redmine@... Date: 2011-04-18T12:06:24+09:00 Subject: [ruby-core:35804] [Ruby 1.9 - Bug #4576] Range#step miss the last value, if end-exclusive and has float number Issue #4576 has been updated by Tomoyuki Chikanaga. test_step_ruby_core_35753 seems depend on platform. On i686-linux it fails. 1) Failure: test_step_ruby_core_35753(TestRange) [/home/chikanaga/opt/ruby-trunk/src/ruby/test/ruby/test_range.rb:190]: <3> expected but was <4>. Rebuild with "cflags=-ffloat-store" option fixes this failure. It seems a "learn floating point number" issue. May i partially revert an testcase of test_step_ruby_core_35753? ---------------------------------------- Bug #4576: Range#step miss the last value, if end-exclusive and has float number http://redmine.ruby-lang.org/issues/4576 Author: Joey Zhou Status: Closed Priority: Normal Assignee: Category: Target version: ruby -v: ruby 1.9.2p180 (2011-02-18) [i386-mingw32] Hi, I find that: * if: range.exclude_end? == true * and: any one in [begin_obj, end_obj, step] is a true Float(f.to_i != f) * and: unless begin_obj + step*int == end_obj * then: the result will miss the last value. for example: p (1...6.3).step.to_a # => [1.0, 2.0, 3.0, 4.0, 5.0], no 6.0 p (1.1...6).step.to_a # => [1.1, 2.1, 3.1, 4.1], no 5.1 p (1...6).step(1.1).to_a # => [1.0, 2.1, 3.2, 4.300000000000001], no 5.4 p (1.0...6.6).step(1.9).to_a # => [1.0, 2.9], no 4.8 p (1.0...6.7).step(1.9).to_a # => [1.0, 2.9, 4.8] p (1.0...6.8).step(1.9).to_a # => [1.0, 2.9, 4.8], no 6.7 Maybe the #step is ok on integers, but there's something wrong if the range is end-exclusive and contain float numbers. -- http://redmine.ruby-lang.org