std.range.iota enhancement: supporting more types (AKA issue 10762)

H. S. Teoh hsteoh at quickfur.ath.cx
Tue Dec 24 11:59:44 PST 2013


On Tue, Dec 24, 2013 at 11:35:49AM -0800, Andrei Alexandrescu wrote:
> On 12/24/13 10:56 AM, Craig Dillabaugh wrote:
> >On Tuesday, 24 December 2013 at 17:10:53 UTC, Andrei Alexandrescu
> >wrote:
[.[..]
> >>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?
> >>
> >>Andrei
> >
> >Doesn't think work, or am I missing something?
> >
> >low + floor( (up-low)/step ) * step
> 
> I doubt it's anything as simple as that. The magnitudes of up, low,
> and step must be taken into account.
[...]

What about low + fmod(up-low, step)*step? Is that better? (Assuming that
fmod would take relative magnitudes into account, of course.)


T

-- 
Only boring people get bored. -- JM


More information about the Digitalmars-d mailing list