<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Feb 27, 2016, at 3:27 PM, Erica Sadun <<a href="mailto:erica@ericasadun.com" class="">erica@ericasadun.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><p class="" style="font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; font-size: 1.1429em; line-height: 1.3125em; margin: 1.3125em 0px;">Under the current implementation, each floating point addition accrues errors. The progression never reaches 2.0. </p><pre class="" style="font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; color: rgb(17, 17, 17); font-size: 16px;"><code class=" lasso hljs" style="display: block; padding: 0.5em; color: rgb(51, 51, 51); background-color: rgb(248, 248, 248);">print(<span class="hljs-built_in" style="color: rgb(0, 134, 179);">Array</span>(<span class="hljs-number" style="color: rgb(0, 153, 153);">1.0</span><span class="hljs-built_in" style="color: rgb(0, 134, 179);">.</span>stride(through: <span class="hljs-number" style="color: rgb(0, 153, 153);">2.0</span>, <span class="hljs-keyword" style="font-weight: bold;">by</span>: <span class="hljs-number" style="color: rgb(0, 153, 153);">0.1</span>)))
<span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">/// Prints [1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9]</span></code></pre><p class="" style="font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; font-size: 1.1429em; line-height: 1.3125em; margin: 1.3125em 0px;">To force the progression to include 2.0, you must add an (ugly) epsilon, as in the following example:</p><pre class="" style="font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; color: rgb(17, 17, 17); font-size: 16px;"><code class=" lasso hljs" style="display: block; padding: 0.5em; color: rgb(51, 51, 51); background-color: rgb(248, 248, 248);">print(<span class="hljs-built_in" style="color: rgb(0, 134, 179);">Array</span>(<span class="hljs-number" style="color: rgb(0, 153, 153);">1.0</span><span class="hljs-built_in" style="color: rgb(0, 134, 179);">.</span>stride(through: <span class="hljs-number" style="color: rgb(0, 153, 153);">2.01</span>, <span class="hljs-keyword" style="font-weight: bold;">by</span>: <span class="hljs-number" style="color: rgb(0, 153, 153);">0.1</span>)))
<span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">/// Prints [1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0]</span></code></pre><p class="" style="font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; font-size: 1.1429em; line-height: 1.3125em; margin: 1.3125em 0px;">This is problematic for the following reasons: </p><ul class="" style="font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; font-size: 16px;"><li class="" style="font-size: 18px;">The name of the calling function “through” suggests the progression will pass <em class="">through</em> the end point before stopping</li><li class="" style="font-size: 18px;">Floating point calls present an extremely common use-case</li><li class="" style="font-size: 18px;">It’s unreasonable to expect developers to consider every case of “will floating point math prevent my progression from actually reaching the end point, which has already been differentiated by using <code class="">through</code> rather than <code class="">to</code>”</li></ul></div></blockquote>As implemented, `stride` is broken for floating-point numbers. Instead of repeatedly adding the `by` interval, it should multiply the interval by successive integral values and add that to the base to avoid accruing error. Your proposal only papers over the problem.</div><div><br class=""></div><div>-Joe</div></body></html>