<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'd probably do this:<div class=""><div style="margin: 0px; line-height: normal; background-color: rgb(1, 43, 54);" class=""><div style="font-family: Menlo; color: rgb(0, 0, 0); margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><span style="color: #ba2da2" class="">precedencegroup</span> FauxTwoPartOperatorPrecedence {</div><div style="margin: 0px; line-height: normal; color: rgb(186, 45, 162);" class=""><span style="color: #000000" class="">&nbsp; </span>associativity<span style="color: #000000" class="">: right</span></div><div style="margin: 0px; line-height: normal;" class="">&nbsp; <span style="color: #ba2da2" class="">higherThan</span>: BitwiseShiftPrecedence</div><div style="margin: 0px; line-height: normal;" class="">}</div><div style="margin: 0px; line-height: normal; color: rgb(186, 45, 162);" class="">public<span style="color: #000000" class=""> </span>struct<span style="color: #000000" class=""> VaE&lt;T&gt; {</span></div><div style="margin: 0px; line-height: normal;" class="">&nbsp; <span style="color: #ba2da2" class="">var</span> value: <span style="color: #4f8187" class="">T</span></div><div style="margin: 0px; line-height: normal;" class="">&nbsp; <span style="color: #ba2da2" class="">var</span> epsilon: <span style="color: #4f8187" class="">T</span></div><div style="margin: 0px; line-height: normal;" class="">}</div><div style="margin: 0px; line-height: normal; color: rgb(0, 132, 0);" class=""><span style="color: #ba2da2" class="">infix</span><span style="color: #000000" class=""> </span><span style="color: #ba2da2" class="">operator</span><span style="color: #000000" class=""> ± : FauxTwoPartOperatorPrecedence&nbsp;</span>// `±` is typed "shift-opt-=", at least with macOS's default QWERTY US keyboard layout</div><div style="margin: 0px; line-height: normal;" class=""><span style="color: #ba2da2" class="">public</span> <span style="color: #ba2da2" class="">func</span> ± &lt;T: <span style="color: #703daa" class="">BinaryFloatingPoint</span>&gt; (value: <span style="color: #4f8187" class="">T</span>, epsilon: <span style="color: #4f8187" class="">T</span>) -&gt; <span style="color: #4f8187" class="">VaE</span>&lt;<span style="color: #4f8187" class="">T</span>&gt; {</div><div style="margin: 0px; line-height: normal;" class="">&nbsp; <span style="color: #ba2da2" class="">return</span> <span style="color: #4f8187" class="">VaE</span>(value: value, epsilon: epsilon)</div><div style="margin: 0px; line-height: normal;" class="">}</div><div style="margin: 0px; line-height: normal;" class=""><span style="color: #ba2da2" class="">public</span> <span style="color: #ba2da2" class="">func</span> == &lt;T: <span style="color: #703daa" class="">BinaryFloatingPoint</span>&gt; (lhs: <span style="color: #4f8187" class="">T</span>, rhs: <span style="color: #4f8187" class="">VaE</span>&lt;<span style="color: #4f8187" class="">T</span>&gt;) -&gt; <span style="color: #703daa" class="">Bool</span> {</div><div style="margin: 0px; line-height: normal;" class="">&nbsp; <span style="color: #ba2da2" class="">return</span> lhs &lt;= (rhs.<span style="color: #4f8187" class="">value</span> + rhs.<span style="color: #4f8187" class="">epsilon</span>) &amp;&amp; lhs &gt;= (rhs.<span style="color: #4f8187" class="">value</span> - rhs.<span style="color: #4f8187" class="">epsilon</span>)</div><div style="margin: 0px; line-height: normal;" class="">}</div><div class=""><br class=""></div></div><div style="margin: 0px; line-height: normal; color: rgb(39, 42, 216);" class="">0.0<span style="color: #000000" class=""> == </span>0.0<span style="color: #000000" class=""> ± </span>0.1<span style="color: #000000" class=""> </span><span style="color: #008400" class="">// true</span></div><div style="margin: 0px; line-height: normal; color: rgb(39, 42, 216);" class="">1.0<span style="color: #000000" class=""> == </span>0.0<span style="color: #000000" class=""> ± </span>0.1<span style="color: #000000" class=""> </span><span style="color: #008400" class="">// false</span></div><div style="margin: 0px; line-height: normal; color: rgb(39, 42, 216);" class="">-0.3<span style="color: #000000" class=""> == </span>0.0<span style="color: #000000" class=""> ± </span>0.5<span style="color: #000000" class=""> </span><span style="color: #008400" class="">// true</span></div><div class=""><span style="color: #008400" class=""><br class=""></span></div></div></div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);" class="">(or use something like `+-`, if you prefer your custom operators to be not quite <i class="">that</i> custom)</div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);" class=""><br class=""></div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);" class="">Hope that helps,</div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);" class="">- Dave Sweeris</div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);" class=""><br class=""></div></div><div><blockquote type="cite" class=""><div class="">On Jun 29, 2017, at 2:20 PM, Gavin Eadie via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">.. agreed but this looks too awful (and is mostly a joke!)<div class=""><br class=""></div><div class=""><div style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo" class="">&nbsp; &nbsp;&nbsp;<span style="color:rgb(186,45,162)" class="">return</span>&nbsp;a &gt;= b.<span style="color:rgb(112,61,170)" class="">nextDown.</span><span style="color:rgb(112,61,170)" class="">nextDown.</span><span style="color:rgb(112,61,170)" class="">nextDown.</span><span style="color:rgb(112,61,170)" class="">nextDown</span>&nbsp;&amp;&amp; a &lt;= b.<span style="color:rgb(112,61,170)" class="">nextUp.</span><span style="color:rgb(112,61,170)" class="">nextUp.</span><span style="color:rgb(112,61,170)" class="">nextUp.</span><span style="color:rgb(112,61,170)" class="">nextUp</span></div></div><div class="gmail_extra"><br class=""></div><div class="gmail_extra">Thanks, friends, for your insights and info .. Gavin</div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Thu, Jun 29, 2017 at 3:30 PM, Taylor Swift via swift-users <span dir="ltr" class="">&lt;<a href="mailto:swift-users@swift.org" target="_blank" class="">swift-users@swift.org</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class=""><div class="h5"><div style="word-wrap:break-word;line-break:after-white-space" class=""><div style="margin:0px;font-stretch:normal;line-height:normal;background-color:rgb(255,255,255)" class=""><br class="">(b) one ULP is almost never a tolerance you want to use. It’s much too small for almost all computations, and too large for most of the remaining ones.</div><div style="margin:0px;font-stretch:normal;line-height:normal;background-color:rgb(255,255,255)" class=""><br class=""></div><div style="margin:0px;font-stretch:normal;line-height:normal;background-color:rgb(255,255,255)" class="">– Steve</div></div></div></div></blockquote></div></div><br class="">______________________________<wbr class="">_________________<br class="">
swift-users mailing list<br class="">
<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank" class="">https://lists.swift.org/<wbr class="">mailman/listinfo/swift-users</a><br class="">
<br class=""></blockquote></div><br class=""></div></div>
_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></div></blockquote></div><br class=""></div></body></html>