<div class="gmail_quote"><div>(with apologies for the random extra level of quoting in the below...)</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="Ih2E3d">
<div class="gmail_quote">On Thu, Mar 13, 2008 at 11:09 AM, Imri Goldberg <<a href="mailto:lorgandon@gmail.com" target="_blank">lorgandon@gmail.com</a>> wrote:</div></div><div class="gmail_quote"><div class="Ih2E3d">
<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
As I said earlier, I'd like static checkers (like Python-Lint) to catch<br>
this sort of cases, whatever the decision may be.<br>
<div></div></blockquote><div></div></div></div></blockquote><div> </div><div>Hmm.  Isn't that tricky?  How does the static checker decide</div><div>whether the objects being compared are floats?  I guess one could<br>
</div><div>be content with catching some cases where the operands to ==</div><div>are clearly floats...  Wouldn't you have to have run-time warnings</div><div>to be really sure of catching all the cases?</div><div><br class="webkit-block-placeholder">
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="gmail_quote"><div class="Ih2E3d"><div>
<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>> It's already too late for Python 3.0.<br>
</div>Still, I believe it is worth discussing.<br>
<div></div></blockquote><div></div></div></div></blockquote><div><br class="webkit-block-placeholder"></div><div> </div><div>Sure.  I didn't mean that to come out in quite the dismissive way it did :).</div><div>Apologies.  Maybe a PEP aimed at Python 4.0 is in order.  If you're open</div>
<div>to the idea of just having some way to enable warnings, it could be</div><div>much sooner.</div><div><br class="webkit-block-placeholder"></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="gmail_quote"><div class="Ih2E3d"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><br>
</div>While checking against a==0.0 (and other similar conditions) before<br>
dividing will indeed protect from outright division by zero, it will<br>
enlarge any error you will have in the computation. I guess it would be<br>
better to do the same check for 'a is small' for appropriate values of<br>
'small'.</blockquote><div></div></div></div></blockquote><div> </div><div>Still, a check for 0.0 is good enough in some cases:  if a is tiny, the</div><div>large intermediate values may appear and then disappear happily</div>
<div>before giving a sensible final result.  These are usually the sort</div><div>of cases where just having division by 0.0 return an infinity</div><div>would have "just worked" too (making the whole "if" redundant), but</div>
<div>that's not (currently!) an option in Python.</div><div><br class="webkit-block-placeholder"></div><div>It's a truism that floating-point equality tests should be avoided, but</div><div>it's just not true that floating-point equality testing is *always* wrong,</div>
<div>and I don't think that Python should make it so.<br></div><div><br class="webkit-block-placeholder"></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="gmail_quote">
<div class="Ih2E3d"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Actually, one of the reasons I thought about this subject in the first<br>
place, was dict lookup for floating point numbers. It seems to me that<br>
it's something you just shouldn't do.<br>
</blockquote><div></div></div></div></blockquote><div> </div><div>So your proposal would presumably include making</div><div><br class="webkit-block-placeholder"></div><div>  x in dict</div><div><br class="webkit-block-placeholder">
</div><div>and</div><div><br class="webkit-block-placeholder"></div><div>  x not in dict</div><div><br class="webkit-block-placeholder"></div><div>errors for any float x, regardless of the contents of the dictionary</div>
<div>(or list, or set, or frozenset, or...) dict?</div><div><br class="webkit-block-placeholder"></div><div>What would you do about Decimals? A Decimal is just another</div><div>floating point format (albeit base 10 instead of base 2); so</div>
<div>presumably all these warnings/errors should apply equally</div><div>to Decimal instances?  If not, why not?</div><div><br class="webkit-block-placeholder"></div><div>I'm not trying to be negative here---as Aahz says, this is an</div>
<div>interesting idea;  I'm just trying to understand exactly how</div><div>things might work.</div><div><br></div><div>Mark</div></div>