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

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Dec 24 13:18:34 PST 2013


On 12/24/13 1:09 PM, H. S. Teoh wrote:
> On Tue, Dec 24, 2013 at 12:57:02PM -0800, Andrei Alexandrescu wrote:
>> On 12/24/13 11:59 AM, H. S. Teoh wrote:
>>> 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.)
>>
>> No, again, I think nothing like that would work. It's hopelessly
>> naive (in addition to being plain wrong for simple inputs like
>> low=1, high=10, step=1).
>>
>> There are combinations of low, high, and step that don't even make
>> progress, i.e. step is sufficiently small compared to low to
>> effectively make low + step == low.
>
> Then what should be returned in that case?

The same as an iota with step zero.

>>          auto next = low + step;
>
> Aren't you accumulating roundoff errors here?

Ideally one addition is all needed for popBack.


Andrei




More information about the Digitalmars-d mailing list