<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">I should also point out:<div class=""><br class=""></div><div class="">(a) your code can be somewhat simpler in Swift. I would probably write something along the lines of:</div><div class=""><br class=""><div class=""><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">func</span> almostEqual&lt;T: <span style="color: #703daa" class="">FloatingPoint</span>&gt;(<span style="color: #ba2da2" class="">_</span> a: <span style="color: #4f8187" class="">T</span>, <span style="color: #ba2da2" class="">_</span> b: <span style="color: #4f8187" class="">T</span>) -&gt; <span style="color: #703daa" class="">Bool</span> {</div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; <span style="color: #ba2da2" class="">return</span> a &gt;= b.<span style="color: #703daa" class="">nextDown</span> &amp;&amp; a &lt;= b.<span style="color: #703daa" class="">nextUp</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">}</div></div></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; 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="">(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></body></html>