On Tue, Dec 17, 2013 at 04:58:10PM +0100, Simen Kjærås wrote: > On 17.12.2013 16:22, Francesco Cattoglio wrote: > >On Monday, 16 December 2013 at 22:53:24 UTC, H. S. Teoh wrote: > >>>What's wrong with having it implemented analogous to > >>>std.random.uniform -- taking a bounds parameter which allows for > >>>open and/or closed at either end, with the default being "[)" ... ? > >>> > >>>By the way, I'd also like to see that open/closed-at-either-end > >>>specialization extended to std.range.iota(). > >> > >>Oooh, do I hear a volunteer for cleaning up iota? ;-) > >> > >>While you're at it, you might as well implement: > >> > >> https://d.puremagic.com/issues/show_bug.cgi?id=10762 > >> > >>:-P > >> > >> > >>T > > > >Well, I might actually volunteer :) > >Any pointer about implementing that enhancement? Can one just forgot > >about the different versions (one for integrals, one for floating > >points) and just implement the One True Iota? > > One problem of OTI (One True Iota) is floating-point inaccuracies. > What does this function return? (hint: it's not 16777217) > > float foo() { > return 16777216f + 1.0f; > } > > So if you want iota(16777217f, 16777245f, 1.0f) to not go into an > infinite loop, you will probably need to special-case > floating-point. If you assume that you can duplicate whatever is > passed to iota, you could do something like this: > > > T _front; > size_t _index; > U _step; > > void popFront() { > ++_index; > if (_front + _index * _step != _front) { > _front += _index * _step; > _index = 0; > } > } > > I don't think even this covers all bases (consider the case where > the inaccuracy of real is > size_t.max). > > I'm playing with writing a new iota now too. Could be fun to see > what different solutions people come up with. [...]
Maybe this should be a community effort. Let each of us come up with a new iota, and we can compare and incorporate each other's ideas to produce the best implementation. How's that? T -- Life is unfair. Ask too much from it, and it may decide you don't deserve what you have now either.
