From: Masahiro TANAKA Date: 2011-10-02T18:30:06+09:00 Subject: [ruby-core:39828] Re: [Ruby 1.9 - Bug #4576] Range#step miss the last value, if end-exclusive and has float number 2011/9/17 Masahiro TANAKA : > --- numeric.c � (revision 33288) > +++ numeric.c � (working copy) > @@ -1690,8 +1690,16 @@ > � � � �} > � � � �else { > � � � � � �if (err>0.5) err=0.5; > - � � � � � n = floor(n + err); > - � � � � � if (!excl || ((long)n)*unit+beg < end) n++; > + � � � � � if (excl) { > + � � � � � � � if (n>0) { > + � � � � � � � � � if (n + � � � � � � � � � � � n = 1; > + � � � � � � � � � else > + � � � � � � � � � � � n = floor(n - err) + 1; > + � � � � � � � } > + � � � � � } else { > + � � � � � � � n = floor(n + err) + 1; > + � � � � � } > � � � � � �for (i=0; i � � � � � � � �rb_yield(DBL2NUM(i*unit+beg)); > � � � � � �} This patch involves a problem: a=(1.0..1-2e-16).step(1.0).to_a; p a #=> [1.0] ; should be [] The following patch would be better. --- numeric.c (revision 33377) +++ numeric.c (working copy) @@ -1690,9 +1690,18 @@ } else { if (err>0.5) err=0.5; - n = floor(n + err); - if (!excl || ((long)n)*unit+beg < end) n++; - for (i=0; i