This is to allow bulk computations to run to completion, with NaNs fromĮrrors propagating to their dependent results without aborting the This, in my triple humble opinion, is incorrect, especially for a IEEE 754 says that “The equality and inequality predicates are Reduce the likelihood of mistaking a NaN for something else. The idea is to make tests return false to In my humble opinion, this behavior is wrong. Username:storchaka”] > nan = float('nan') [quote=“Serhiy Storchaka, post:6, topic:24656, full:true, PS: sorry for the way I’m posting references, but suddenly I can’t post links… Is there any chance to change the behavior of comparison with NaN so they will raise an exception instead? This, in my triple humble opinion, is incorrect, especially for a language that can raise exceptions. IEEE 754 says that “The equality and inequality predicates are non-signaling.”: Or better, it can be false, but it can also be true! You can’t know, since nans are indeterminate, so they could also have the same value. So, the fact that nan = nan is False is… false. Of course, moving the zero from the other side of the equation is not permitted in mathematics, but I leave to the reader a more sophisticated explaining why nan is indeterminate. Means that nan can have any value, since 0 * nan = 0 NaN mathematically is an indeterminate form: Not a mathematical, but I’ll try my best. If you know it is (a) reliable and (b) a useful performance hack.Ĭameron Simpson Storchaka: > nan = float('nan') Rely on the object itself toĪnd you can, if you truly know the domain sufficiently, write: a is b or a = b Knows its own semantics, not in the caller’s mind, who may have a The point here being that this optimisation belongs in the class, which Return self is other or all-the-salient-internal-values-are-equal Implement _eq_ as: def _eq_(self, other): If you have a class where a full on values based equality test isĮxpensive and you know that identify implies equality, you can The flip side of Aohan’s example of _eq_ returning False is that Pointless optimisation of a well defined idea ( = in this case). For example, I can imagine a case for making sentinel valuesīut Chris’ post is basicly saying to you: write what you mean.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |