<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=""><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 class=""><br class=""></div><div><blockquote type="cite" class=""><div class="">On Apr 9, 2016, at 6:59 PM, 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="">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" 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 style="" class="">&nbsp; &nbsp; </span><span style="color:#bb2ca2" class="">if</span><span style="" class=""> </span><span class="">someTestInvolving</span><span style="" class="">(i) { </span><span style="color:#bb2ca2" class="">break</span><span style="" 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 style="" class="">&nbsp; &nbsp; </span><span style="color:#bb2ca2" class="">if</span><span style="" class=""> </span><span class="">someTestInvolving</span><span style="" class="">(i) { </span><span style="color:#bb2ca2" class="">break</span><span style="" 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=""></body></html>