<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);">&nbsp; &nbsp; @floatingPointComparisonTolerance = 0.001 //tuned for a specific situation.</span></div><div><br>&nbsp; &nbsp; &nbsp;if a == b {} &nbsp; &nbsp; // this statement is affected..</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div><div>&nbsp; &nbsp; &nbsp; If &nbsp; c != d {} &nbsp; // ..and also this one. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div><div>&nbsp; &nbsp; <span style="background-color: rgba(255, 255, 255, 0);">&nbsp;@resetFloatingPointComparisonTolerance &nbsp;// default is none</span></div><div><span style="background-color: rgba(255, 255, 255, 0);">&nbsp; &nbsp; &nbsp;if a == b &nbsp; // here, no longer a tolerance band is active.</span></div><div><span style="background-color: rgba(255, 255, 255, 0);">&nbsp; &nbsp; &nbsp;</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>&nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp;&nbsp;</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 &lt;<a href="mailto:jgroff@apple.com">jgroff@apple.com</a>&gt; 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 &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; 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> &nbsp;&nbsp;@floatingPointComparisonTolerance = 0.001</span><br></blockquote><blockquote type="cite"><span> &nbsp;&nbsp;&nbsp;// all source that follows this will be compiled with this value</span><br></blockquote><blockquote type="cite"><span> &nbsp;&nbsp;&nbsp;// until reset or another value is specified with this directive.</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span> &nbsp;&nbsp;if fp1 == fp2 &nbsp;&nbsp;&nbsp;// will be evaluated with the above specified tolerance. </span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span> &nbsp;&nbsp;for v in minival.stride(to: maxival, by: 0.1)</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span> &nbsp;&nbsp;for e from -1.0 to 123.45 by 0.1 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// also in loops of course, as here in the for loop &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;variant I will propose.</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span> &nbsp;&nbsp;@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>