<p dir="ltr">Ok, but you're missing a huge issue, which is that according to the rule you suggest, 0.0 is not close to any non-zero value. Handing such a function to users and claiming it's the one "is close" predicate they need is going to produce a lot of sad and confused users.</p>
<p dir="ltr">I don't want to step on your positive let's-fix-it attitude, I think that's great, but... I do think you are really underestimating the complexity of the problem.</p>
<p dir="ltr">The right way to handle comparison with zero, or comparison between epsilon and negative epsilon, etc, really depends on the context. For common unit test cases it may even make sense to prefer a non-symmetric predicate -- e.g. if you're expecting 0 then 1e-100 is usually fine, but if you're expecting 1e-100 then getting 0 might be a huge problem.</p>
<p dir="ltr">-n</p>
<div class="gmail_quote">On 13 Jan 2015 01:19, "Chris Barker" <<a href="mailto:chris.barker@noaa.gov">chris.barker@noaa.gov</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">OK,<div><br></div><div>I tossed together an example implementation:</div><div><br></div><div><a href="https://gist.github.com/PythonCHB/6e9ef7732a9074d9337a" target="_blank">https://gist.github.com/PythonCHB/6e9ef7732a9074d9337a</a><br></div><div><br></div><div>Simple enough, and seems to work fine for complex, too, out of the box (just using plain old abs). I haven't tried it, but it should work for integers (and decimal?), too, though less need for that anyway.</div><div><br></div><div>The Boost docs talk about overflow issues, but I can't trigger them, nor see where there would show up, except for if the two values tested were REALLY far apart, which isn't really the use case we're worried about. But I could very well be missing something, I'm no FP expert.</div><div><br></div><div>It would probably be good if someone that understands these things better than me came up with some near-pathological test cases.</div><div><br></div><div>Nathaniel, thanks for the pointer to the Boost docs -- I like this much more than numpy's weird atol+rtol approach.</div><div><br></div><div>-Chris</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jan 12, 2015 at 3:34 PM, Chris Barker <span dir="ltr"><<a href="mailto:chris.barker@noaa.gov" target="_blank">chris.barker@noaa.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><div class="gmail_quote"><span>On Mon, Jan 12, 2015 at 2:56 PM, 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"><div dir="ltr">But should probably use complex abs().</div></blockquote><div><br></div></span><div>maybe, it does add complication  -- I'd need to look more closely at the Boost code. And I'm trying to think if there are any numerical FP issues that would arise from that -- I'm no expert.</div><span><div><br></div><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"><div dir="ltr">Adding it to cmath makes sense (if adding it to math happens).</div></blockquote><div><br></div></span><div>sure.</div><div><br></div><div>And I hate to bring this up, but any reason for a cmath.nan and cmath.inf ?</div><span><div><br></div><div><br></div><div>I wrote:</div><div><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 looks like they start with two, but end up with<br><span style="font-size:13px">"the implementation is using modified version of the equations (1) and (2) where all underflow, overflow conditions could be guarded safely"</span></blockquote></div><div><span style="font-size:13px"><br></span></div></span><div>oops, they do indeed keep both versions, a "weak" and "strong" one.</div><div><br></div><div>essentially, "is the error small enough relative to both input values, or only one of them. Fairly subtle difference, but I like the "strong" definition, as it gives the same result regardless of input order. though it does guarantee a bit of maybe unnecessary computation.</div><div><br></div><div>I'm going to play with code a bit now.</div><span><font color="#888888"><div><br></div><div>-Chris</div><div><br></div><div> </div></font></span></div><span>-- <br><div><br>Christopher Barker, Ph.D.<br>Oceanographer<br><br>Emergency Response Division<br>NOAA/NOS/OR&R            <a href="tel:%28206%29%20526-6959" value="+12065266959" target="_blank">(206) 526-6959</a>   voice<br>7600 Sand Point Way NE   <a href="tel:%28206%29%20526-6329" value="+12065266329" target="_blank">(206) 526-6329</a>   fax<br>Seattle, WA  98115       <a href="tel:%28206%29%20526-6317" value="+12065266317" target="_blank">(206) 526-6317</a>   main reception<br><br><a href="mailto:Chris.Barker@noaa.gov" target="_blank">Chris.Barker@noaa.gov</a></div>
</span></div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div><br>Christopher Barker, Ph.D.<br>Oceanographer<br><br>Emergency Response Division<br>NOAA/NOS/OR&R            <a href="tel:%28206%29%20526-6959" value="+12065266959" target="_blank">(206) 526-6959</a>   voice<br>7600 Sand Point Way NE   <a href="tel:%28206%29%20526-6329" value="+12065266329" target="_blank">(206) 526-6329</a>   fax<br>Seattle, WA  98115       <a href="tel:%28206%29%20526-6317" value="+12065266317" target="_blank">(206) 526-6317</a>   main reception<br><br><a href="mailto:Chris.Barker@noaa.gov" target="_blank">Chris.Barker@noaa.gov</a></div>
</div>
<br>_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" target="_blank">http://python.org/psf/codeofconduct/</a><br></blockquote></div>