[swift-evolution] Feature proposal: Range operator with step

Rainer Brockerhoff rainer at brockerhoff.net
Thu Mar 31 13:37:28 CDT 2016


On 3/31/16 15:29, Stephen Canon via swift-evolution wrote:
> 
>> On Mar 31, 2016, at 11:16 AM, Rainer Brockerhoff via swift-evolution <swift-evolution at swift.org> wrote:
>>
>> On 3/31/16 15:06, Dave Abrahams via swift-evolution wrote:
>>>...
>>> I think I want to hear Steve Canon's input on this one.  I defer to him
>>> on most things numeric.
>>
>> In particular, should Steve confirm that the IEEE754 Decimal128 format
>> is being worked on, and if simple decimal constants like those in
>> 	`for i in stride(from: 0.0, to: DBL_MAX, by: DBL_MIN) { }`
>> will be type-inferred as Decimal128, all that would "just work".
> 
> Decimal is something that I would like to see happen.  However, I
> would not expect any such proposal to result in that loop being type
> inferred to Decimal, since the to: and by: values are explicitly
> (binary floating-point) Doubles.

Oopsie. Pressed 'send' accidentally before re-editing this to
	for i in stride(from: 0.0, to: 1.0, by: 0.1)...
Sorry about that.

> I also don’t think that such a loop is particularly useful.  For
> floating-point types, something like stride(from: T, to: T, steps:
> Int) seems safer and more workable to me (this is just my immediate
> reaction, I haven’t thought this through in detail, and am likely to
> change my mind if someone makes a good case).

`steps:` is OK for me too, though certain people would probably be
compelled to write, say,
	stride(from: floatA, to: floatB, steps: (floatB-floatA/0.1) )
perish forbid.

-- 
Rainer Brockerhoff  <rainer at brockerhoff.net>
Belo Horizonte, Brazil
"In the affairs of others even fools are wise
In their own business even sages err."
http://brockerhoff.net/blog/



More information about the swift-evolution mailing list