A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/attachments/20100328/0581bad0/attachment.html below:

A good summary on floating point comparison algorithms can be found at <div><br></div><div><a href="http://www.boost.org/doc/libs/1_34_0/libs/test/doc/components/test_tools/floating_point_comparison.html">http://www.boost.org/doc/libs/1_34_0/libs/test/doc/components/test_tools/floating_point_comparison.html</a><br>
<br></div><div>I, too, redefine almostEquals so that the comparison is more robust</div><div><br></div><div>+1</div><div><br><div class="gmail_quote">On Sun, Mar 28, 2010 at 2:06 AM, Steven D&#39;Aprano <span dir="ltr">&lt;<a href="mailto:steve@pearwood.info">steve@pearwood.info</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im">On Sun, 28 Mar 2010 02:54:19 pm Charles McCreary wrote:<br>
&gt; Perhaps not just absolute but relative tolerance, e.g.:<br>
&gt;<br>
&gt; def isclose(x, y, rtol=1.e-5, atol=1.e-8):<br>
&gt;     return abs(x-y) &lt;= atol + rtol * abs(y)<br>
<br>
</div>I&#39;m not sure why you add the tolerances like that. Surely a more<br>
appropriate approach is to compare the values against the tolerances<br>
individually, and return True if they meet either condition.<br>
<br>
For what it&#39;s worth, here&#39;s a recipe I wrote for approximately equal,<br>
following someone&#39;s complaint on comp.lang.python that Python has no<br>
approximately-equal operator.<br>
<br>
<a href="http://code.activestate.com/recipes/577124-approximately-equal/" target="_blank">http://code.activestate.com/recipes/577124-approximately-equal/</a><br>
<br>
Comments and criticism welcome.<br>
<br>
I&#39;ve never found unittest.TestCase.assertAlmostEqual to be useful. I<br>
generally write my own comparison function, then call:<br>
<br>
assert_(compare(x, y))<br>
<br>
as needed. I&#39;m +0.5 on Michael&#39;s suggested change -- it will make<br>
assertAlmostEqual marginally more useful, which is a plus, but I&#39;m not<br>
sure that absolute tolerances are better than relative. But how general<br>
do we want to be? &quot;Almost equal&quot; means something different to everyone.<br>
<div class="im"><br>
<br>
<br>
&gt; On Fri, Mar 26, 2010 at 7:59 PM, Michael Foord<br>
&lt;<a href="mailto:fuzzyman@voidspace.org.uk">fuzzyman@voidspace.org.uk</a>&gt;wrote:<br>
&gt; &gt; Hello all,<br>
&gt; &gt;<br>
&gt; &gt; A user has suggested an optional argument to<br>
&gt; &gt; unittest.TestCase.assertAlmostEqual for specifying a maximum<br>
&gt; &gt; difference between the expected and actual values, instead of using<br>
&gt; &gt; rounding.<br>
</div>[snip]<br>
<br>
<br>
<br>
--<br>
<font color="#888888">Steven D&#39;Aprano<br>
</font><div><div></div><div class="h5">_______________________________________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org">Python-Dev@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-dev" target="_blank">http://mail.python.org/mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="http://mail.python.org/mailman/options/python-dev/charles.r.mccreary%40gmail.com" target="_blank">http://mail.python.org/mailman/options/python-dev/charles.r.mccreary%40gmail.com</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Charles McCreary P.E.<br>CRM Engineering<br>903.643.3490 - office<br>903.224.5701 - mobile/GV<br>
</div>

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4