On Tue, Dec 24, 2013 at 09:10:53AM -0800, Andrei Alexandrescu wrote: > On 12/24/13 5:09 AM, Joseph Rushton Wakeling wrote: > >On 24/12/13 13:58, monarch_dodra wrote: > >>I think you are missing the point of what happens if the step is not > >>1 (or if the passed in type can have fractional input). EG: > >> > >>iota(0, 105, 10); > >>or > >>iota(0, 10.5); > >> > >>In this case, "back" should be 100, and not 95. To compute back, you > >>need to be able to evaluate length, and to add length*inc to front. > > > >Oh, snap. Have we been working on the same problems for too long? > >:-) > > The integral cases are easy. We need to crack the floating point case: > given numbers low, up, and step, what's the closest number smaller > than up that's reached by repeated adds of step to low? [...]
The closest number is simply step*floor((up-low)/step). There's probably a better way to write that expression that avoids bad roundoff errors, though. T -- Why can't you just be a nonconformist like everyone else? -- YHL