From: "NARUSE, Yui" Date: 2011-09-17T15:56:35+09:00 Subject: [ruby-core:39604] Re: [Ruby 1.9 - Bug #4576] Range#step miss the last value, if end-exclusive and has float number (2011/09/17 9:07), Tanaka Akira wrote: > So my understanding of this problem is that no one implemented > proper exclude_end support with well considered float errors, yet. In my current understanding, the error is fabs(beg) * epsilon + fabs(unit) * epsilon * n + fabs(end) * epsilon = (fabs(beg) + fabs(end) + fabs(end-beg)) * epsilon // ignore error over unit*n -> end-beg But the correct error may be less than it. diff --git a/numeric.c b/numeric.c index 18f5e1c..459e209 100644 --- a/numeric.c +++ b/numeric.c @@ -1691,7 +1691,9 @@ ruby_float_step(VALUE from, VALUE to, VALUE step, int excl) else { if (err>0.5) err=0.5; n = floor(n + err); - if (!excl || ((long)n)*unit+beg < end) n++; + err = (fabs(beg) + fabs(end) + fabs(end-beg)) * epsilon; + if (err>0.5) err=0.5; + if (!excl || (long)n*unit+beg+err < end) n++; for (i=0; i