<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>They are not random tolerances and also not global as one</div><div>can set a specific (fine tuned) tolerance bandwidth for 1 or more</div><div>statements, following such a directive, until another, or a reset.</div><div>e.g.</div><div><span style="background-color: rgba(255, 255, 255, 0);"> @floatingPointComparisonTolerance = 0.001 //tuned for a specific situation.</span></div><div><br> if a == b {} // this statement is affected..</div><div> </div><div> If c != d {} // ..and also this one. </div><div> <span style="background-color: rgba(255, 255, 255, 0);"> @resetFloatingPointComparisonTolerance // default is none</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"> if a == b // here, no longer a tolerance band is active.</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"> </span></div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div>So, it is not global, but only in effect for statements in between/after these directives.</div><div><br></div><div>Nothing new here. Comparison tolerance has been in use in e.g. APL since ca 1975, see here for a good explanation.</div><div><br></div><div><a href="http://microapl.com/apl_help/ch_020_070_150.htm">http://microapl.com/apl_help/ch_020_070_150.htm</a></div><div><br></div><div>kind regards</div><div>TedvG</div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div> </div><div> </div><div><br><div><br><div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="background-color: rgba(255, 255, 255, 0);">ted van gaalen</span></div><div><div apple-content-edited="true"><div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);"></span></font></div></div></div></div></div></div></div><div><br>On 01 Mar 2016, at 21:00, Joe Groff <<a href="mailto:jgroff@apple.com">jgroff@apple.com</a>> wrote:<br><br></div><blockquote type="cite"><div><span></span><br><blockquote type="cite"><span>On Mar 1, 2016, at 10:28 AM, ted van gaalen via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>in relation to my message about handling floating point number comparisation tolerance in e.g. a .stride function, wouldn't this be better handled by a compiler directive?</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>For example:</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span> @floatingPointComparisonTolerance = 0.001</span><br></blockquote><blockquote type="cite"><span> // all source that follows this will be compiled with this value</span><br></blockquote><blockquote type="cite"><span> // until reset or another value is specified with this directive.</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span> if fp1 == fp2 // will be evaluated with the above specified tolerance. </span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span> for v in minival.stride(to: maxival, by: 0.1)</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span> for e from -1.0 to 123.45 by 0.1 // also in loops of course, as here in the for loop variant I will propose.</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span> @resetFloatingPointComparisonTolerance()</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>At any time, you should be able to change @floatingPointComparisonTolerance,</span><br></blockquote><blockquote type="cite"><span>which will have its effect on source lines that follow it.</span><br></blockquote><span></span><br><span>"Floats are inaccurate, let's just add random tolerances in" is a naive outlook on floating-point numerics. There are invariants which carefully-written floating point code can expect to hold in a lot of cases. We could provide tolerant comparison operations, but global state would be a poor way of doing so, and imposing this behavior on the standard comparison operators would be problematic. It'd be better to provide methods IMO, so that e.g. `fp1.equals(fp2, tolerance: 0x1p-44)` performed a comparison with a proportional tolerance check.</span><br><span></span><br><span>-Joe</span></div></blockquote></body></html>