Stuart Halloway
added a comment - 01/Mar/13 10:08 AM Range is incremental by design, and that is how floats work. Something with the desired behavior would need to be a different fn with a different name.

"Returns a lazy seq of nums from start (inclusive) to end (exclusive), by step"

What specifically about that wording specifically suggests that the implementation will use naive increment-and-recurse behaviour? My reading is that the function will return a lazy sequence of numbers from start to end separated by step, not separated by 'almost step'.

Stephen Nelson
added a comment - 03/Mar/13 2:38 PM "Returns a lazy seq of nums from start (inclusive) to end (exclusive), by step"
What specifically about that wording specifically suggests that the implementation will use naive increment-and-recurse behaviour? My reading is that the function will return a lazy sequence of numbers from start to end separated by step, not separated by 'almost step'.
This implementation leads to unexpected behaviour with bounds:
=> (count (range 0 100 1))
100
=> (count (range 0 10 0.1))
101
http://www.ima.umn.edu/~arnold/455.f96/disasters.html

Hope that helps any disillusioned float users out there, or just pass in BigDecimals to range instead of floats... I would go so far as to say using floats with range as it stands is almost always going to end in tears (or worse as Stephen describes ).

Timothy Pratley
added a comment - 29/Mar/13 5:09 PM range could avoid this issue cleanly by converting floats to bigdecimals (let me know if you think this is a good idea?)
I ran into this problem recently, and have to say it was pretty ugly. This is how I avoided the issue:
(defn rangef
"Returns a sequence of n numbers from start to end inclusive."
[start end n]
(for [i (range 0 n)]
(+ start (* i (/ (- end start) (dec n))))))
Hope that helps any disillusioned float users out there, or just pass in BigDecimals to range instead of floats... I would go so far as to say using floats with range as it stands is almost always going to end in tears (or worse as Stephen describes ).