<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 27, 2015 at 11:20 AM, Guido van Rossum <span dir="ltr"><<a href="mailto:guido@python.org" target="_blank">guido@python.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">It feels like absolute tolerance is a completely different test. And it is a much simpler test for which w don't need a helper function -- it's just abs(x) < tolerance.</blockquote></div><div class="gmail_extra"><br></div>+1</div><div class="gmail_extra"><br>Just as a point of reference, APL and its derivatives use tolerant comparison in the default equal (=) operator.  The definition that they use for finite x and y is simply</div><div class="gmail_extra"><br></div><div class="gmail_extra">  x = y <=> abs(x-y) <= tol * max(abs(x), abs(y))</div><div class="gmail_extra"><br></div><div class="gmail_extra">The tolerance can be adjusted globally or in some languages (such as J [1]) in the expression using additional syntax.</div><div class="gmail_extra"><br></div><div class="gmail_extra">In J, the default tolerance is 2**-44, which is about 5.7e-14.  APL restricts the range of tolerance values to 0 through 2**-32.</div><div class="gmail_extra"><br></div><div class="gmail_extra">I would be +0 on adding something like</div><div class="gmail_extra"><br></div><div class="gmail_extra">def tolerant_equal(x, y, tol=2**-44):</div><div class="gmail_extra">    return abs(x-y) <= tol * max(abs(x), abs(y))</div><div class="gmail_extra"><br></div><div class="gmail_extra">(name subject to bikeshedding)</div><div class="gmail_extra"><br></div><div class="gmail_extra">to math, but -1 on anything more complicated.  I would rather see</div><div class="gmail_extra"><br></div><div class="gmail_extra">if tolerant_equal(x, y) or abs(x-y) <= 1e-10: ..</div><div class="gmail_extra"><br></div><div class="gmail_extra">than</div><div class="gmail_extra"><br></div><div class="gmail_extra">if tolerant_equal(x, y, atol=1e-10): ..<br></div><div class="gmail_extra"> </div><div class="gmail_extra"><br></div><div class="gmail_extra">[1] <a href="http://www.jsoftware.com/help/dictionary/d000.htm">http://www.jsoftware.com/help/dictionary/d000.htm</a>  </div><div class="gmail_extra">[2] <a href="http://www.dyalog.com/uploads/documents/Papers/tolerant_comparison/tolerant_comparison.htm">http://www.dyalog.com/uploads/documents/Papers/tolerant_comparison/tolerant_comparison.htm</a></div></div>