From: Tanaka Akira Date: 2011-09-17T09:07:03+09:00 Subject: [ruby-core:39595] Re: [Ruby 1.9 - Bug #4576] Range#step miss the last value, if end-exclusive and has float number 2011/9/17 Tanaka Akira : > > I don't think the patch is a appropriate fix for this problem. > > The test, "n*unit+beg < end", is fragile. I made a sample script to show the fragileness on x86_64 to explain this is not the x86 80bit float issue. (x86_64 doesn't use 80bit float.) % ./ruby -v ruby 1.9.4dev (2011-09-15 trunk 33274) [x86_64-linux] % ./ruby -e ' h = Hash.new(0) 1000.times { a = rand b = a+rand*10000 s = (b - a) / 10 l = (a...b).step(s).to_a.length h[l] += 1 } p h ' {10=>940, 11=>60} In this script, the result length vary. Some people may think this is not a bug because floating point calculation may have errors. But in the following script, which changes "a...b" to "a..b" from the above script, the result length doesn't vary. % ./ruby -e ' h = Hash.new(0) 1000.times { a = rand b = a+rand*10000 s = (b - a) / 10 l = (a..b).step(s).to_a.length h[l] += 1 } p h ' {11=>1000} This is because we tried to consider float errors in Numeric#step for Ruby 1.8. [ruby-dev:20163] The implementation is extracted and reused for Range#step for Ruby 1.9. [ruby-dev:37691] r21298 The exclude_end support in the implementation is new since Numeric#step don't have correspondence to exclude_end. So my understanding of this problem is that no one implemented proper exclude_end support with well considered float errors, yet. -- Tanaka Akira