I have a problem with the way floating point ranges work with striding:
1.0.stride(through: 2.0, by: 0.1)
returns the sequence [1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9].
Documentation: "It returns the sequence where last is less than or equal to end
."
(And yes, the same issue exists with tradition C-style for loops).
Would it be really horrible if the implementation and definition was changed to:
"It returns the sequence where last is greater than or equal to end
?"
This would offer no change for integers, and include 2.0 for floating point sequences.
Alternatively, could there be decimalStride? Using Double but a rounding system with a fixed number of decimal places (e.g. 1, 2, 3), to ensure at least the end point is hit? It might look like:
1.0.stride(through: 2.0, by: 0.1, places: 1)
I know there have been several discussions on-list about decimal number systems (Re: Is there a need for a Decimal type?) as well, but this could fix an ongoing annoyance without a major change.
Thanks for your thoughts,