From: Daniel Berger Date: 2007-05-30T11:55:17+09:00 Subject: Range#each and stringified floats - bug or feature? Hi all, Ruby 1.8.6 OS X 10.4.9 I searched the archives but didn't find anything definitive. Is the following behavior a bug or feature? irb(main):001:0> r1 = Range.new(1.0, 3.0) => 1.0..3.0 irb(main):002:0> r2 = Range.new("1.0", "3.0") => "1.0".."3.0" irb(main):003:0> r1.each{ |r| p r } TypeError: can't iterate from Float from (irb):3:in `each' from (irb):3 irb(main):004:0> r2.each{ |r| p r } "1.0" "1.1" "1.2" "1.3" "1.4" "1.5" "1.6" "1.7" "1.8" "1.9" "2.0" "2.1" "2.2" "2.3" "2.4" "2.5" "2.6" "2.7" "2.8" "2.9" "3.0" This feels inconsistent to me, because I'm not sure what the precision rules are. More precise floats will give you different behavior. I *think* the behavior is to round to the nearest .1 of the longest mantissa, but that theory falls down as soon as the mantissas don't match: irb(main):009:0> Range.new("1.0", "1.345").each{ |r| p r } "1.0" "1.1" "1.2" ... "999.9" # ??? Bug, right? Dan