<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">I understand (and agree with) 3/4 of that… Why do we want to prevent striding *to* an infinity? I mean, yeah it’ll take a long time to get there, but with the new floating point stride code, a floating point value will *eventually* “overflow” into infinity (or `iteration += 1` will overflow and crash), it’s just that at that point there isn’t a straight-forward way to go the other direction anymore.<div class=""><br class=""><div class="">Actually, striding from an infinity should be ok, too, as long as it’s not the actual starting point:<div class=""><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">let</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">&nbsp;x = -</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">Double</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">.infinity ...&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);" class="">0.0</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures;" class="">// Big Problems in, um, Non-Little Loops… or something… (and apologies to Kurt Russell)</span></div></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> x = -</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Double</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">.infinity &lt;.. </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0.0</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">// starts at `nextafter(start, end)` (-1.797693134862316e+308, in this case)</span></div></div><div class=""><br class=""></div><div class="">If the infinities are definitely out even as exclusive endpoints, can the floating point types get min/max properties like the integer types have?</div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> x = </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Double</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">.min ...&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">Double</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.max</span>&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures" class="">// same as -1.797693134862316e+308 ...&nbsp;</span>1.797693134862316e+308, but way easier to write</div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">let</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">&nbsp;x =&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class=""><span style="color: rgb(112, 61, 170);" class="">Float</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.min ...&nbsp;<span style="color: rgb(112, 61, 170);" class="">Float</span><span style="font-variant-ligatures: no-common-ligatures;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">.max</span>&nbsp;</span><span style="color: rgb(0, 132, 0); font-variant-ligatures: no-common-ligatures;" class="">// same as -3.402823e+38<span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;... 3.402823e+38</span></span></span></span></div></div><div class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><span style="color: rgb(0, 132, 0); font-variant-ligatures: no-common-ligatures;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><br class=""></span></span></span></span></div><div class="">- Dave Sweeris</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Apr 10, 2016, at 12:05 AM, Xiaodi Wu &lt;<a href="mailto:xiaodi.wu@gmail.com" class="">xiaodi.wu@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="white-space:pre-wrap" class="">We will be proposing exactly that which you've put in parentheses, i.e. floating point types will get their own strides, and it will be a precondition failure to try to stride from or to infinity or nan :)<br class=""></div><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Sun, Apr 10, 2016 at 4:47 AM &lt;<a href="mailto:davesweeris@mac.com" class="">davesweeris@mac.com</a>&gt; wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><div class="">It’s not a matter of floating point error accumulation… At least on my machine, once a Double hits +/-∞, there’s no way that I know of to get back to normal floating point numbers. That is to say, for *all* normal, finite values of x, "-Double.infinity + x" will just return “-inf". If x is to equal Double.infinity, Double.NaN, or Double.quietNaN, then it’ll return “nan” (which, incidentally, will fail the regular equality test… Double.NaN isn’t even equal to itself; I think checking the floating point class is the way to do it).</div><div class=""><br class=""></div><div class="">I could easily be missing something, but AFAICT the only way to always get the correct sequence (without splitting the floating point types off into their own thing) is either have a negative stride swap start and end *before* the StrideTo starts generating values (that is, *not* by just calling `.reverse()` on something with a positive stride), or to allow “0 ..&lt; -Double.infinity” to be a valid range (with the negative stride being implied).</div><div class=""><br class=""></div><div class="">- Dave Sweeris</div></div><div style="word-wrap:break-word" class=""><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><div class="">On Apr 9, 2016, at 6:59 PM, Xiaodi Wu &lt;<a href="mailto:xiaodi.wu@gmail.com" target="_blank" class="">xiaodi.wu@gmail.com</a>&gt; wrote:</div><br class=""><div class=""><div style="white-space:pre-wrap" class="">Yikes. Not too concerned about the infinite loop issue, as floating point strides when fixed to avoid error accumulation will necessarily enforce a finite number of steps. However, you're talking a regular, not-at-all-lazy Array being returned? That would be not good at all...<br class=""></div><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Sun, Apr 10, 2016 at 12:29 AM Dave via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Apr 9, 2016, at 4:33 AM, Haravikk via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class=""><div class=""><div style="word-wrap:break-word" class=""><div class="">While I’m in favour of the basic idea I think the operator selection is too complex, and I’m not sure about the need for negative strides. Really all I want are the following:</div><div class=""><br class=""></div><div class=""><font face="Monaco" class=""><span style="white-space:pre-wrap" class="">        </span>(0 ... 6).striding(by: 2)<span style="white-space:pre-wrap" class="">        </span>// [0, 2, 4, 6]<span style="white-space:pre-wrap" class="">                </span>x from 0 to 6</font></div><div class=""><font face="Monaco" class=""><span style="white-space:pre-wrap" class="">        </span>(0 ..&lt; 6).striding(by: 2)<span style="white-space:pre-wrap" class="">        </span>// [0, 2, 4]<span style="white-space:pre-wrap" class="">                </span>x from 0 while &lt;6</font></div><div class=""><font face="Monaco" class=""><span style="white-space:pre-wrap" class="">        </span>(6 ... 0).striding(by: 2)<span style="white-space:pre-wrap" class="">        </span>// [6, 4, 2, 0]<span style="white-space:pre-wrap" class="">                </span>x from 6 to 0</font></div><div class=""><font face="Monaco" class=""><span style="white-space:pre-wrap" class="">        </span>(6 ..&gt; 0).striding(by: 2)<span style="white-space:pre-wrap" class="">        </span>// [6, 4, 2]<span style="white-space:pre-wrap" class="">                </span>x from 6 while &gt;0</font></div><div class=""><br class=""></div><div class="">Everything else should be coverable either by flipping the order, or using .reverse(). The main advantage is that there’s only one new operator to clarify the 6 ..&gt; 0 case, though you could always just reuse the existing operator if you just interpret it as “x from 6 to, but not including, 0"</div></div></div></blockquote></div><br class=""></div><div style="word-wrap:break-word" class=""><div class="">`.reverse()` returns an array, though, not a StrideTo&lt;&gt;, which means it’ll get in an infinite loop on infinite sequences. This works fine:</div><div class=""><span class=""><span class=""><div style="font-family:Menlo;margin:0px;line-height:normal" class=""><div style="margin:0px;line-height:normal" class=""><span style="color:#bb2ca2" class="">for</span><span class=""> i </span><span style="color:#bb2ca2" class="">in</span><span class=""> </span><span style="color:#31595d" class="">stride</span><span class="">(from: </span><span style="color:#272ad8" class="">0.0</span><span class="">, to: </span><span style="color:#703daa" class="">Double</span><span class="">.infinity, by: </span><span style="color:#703daa" class="">M_PI</span><span class="">) {</span></div><div style="margin:0px;line-height:normal;color:rgb(49,89,93)" class=""><span class="">&nbsp; &nbsp; </span><span style="color:#bb2ca2" class="">if</span><span class=""> </span><span class="">someTestInvolving</span><span class="">(i) { </span><span style="color:#bb2ca2" class="">break</span><span class=""> }</span></div><div style="margin:0px;line-height:normal" class=""><span class="">&nbsp; &nbsp; ...</span></div><div style="margin:0px;line-height:normal" class=""><span class="">}</span></div><div class=""><span class=""><br class=""></span></div></div><div class=""><span class="">But this never even starts executing the loop because of the infinite loop inside `.reverse()`:</span></div><div class=""><span class=""><div style="margin:0px;line-height:normal;font-family:Menlo" class=""><span style="color:#bb2ca2" class="">for</span><span class=""> i </span><span style="color:#bb2ca2" class="">in</span><span class=""> </span><span style="color:#31595d" class="">stride</span><span class="">(from: -</span><span style="color:#703daa" class="">Double</span><span class="">.infinity, to: </span><span style="color:#272ad8" class="">0.0</span><span class="">, by: </span><span style="color:#703daa" class="">M_PI</span><span class="">).</span><span style="color:#3d1d81" class="">reverse</span><span class="">() {</span></div><div style="margin:0px;line-height:normal;font-family:Menlo;color:rgb(49,89,93)" class=""><span class="">&nbsp; &nbsp; </span><span style="color:#bb2ca2" class="">if</span><span class=""> </span><span class="">someTestInvolving</span><span class="">(i) { </span><span style="color:#bb2ca2" class="">break</span><span class=""> }</span></div><div style="font-family:Menlo;margin:0px;line-height:normal" class=""><span class="">&nbsp; &nbsp;&nbsp;...</span></div><div style="margin:0px;line-height:normal;font-family:Menlo" class="">}</div></span></div></span></span></div><div class=""><br class=""></div><div class="">- Dave Sweeris</div></div>_______________________________________________<br class="">
swift-evolution mailing list<br class="">
<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
</blockquote></div>
</div></blockquote></div><br class=""></div></blockquote></div>
</div></blockquote></div><br class=""></div></div></div></div></body></html>