On 12.07.2014 18:35, Steven D'Aprano wrote: > If you said, "for many purposes, one should not compare floats for > equality, but should use some sort of fuzzy comparison instead" then I > would agree with you. But your insistence that equality "always" is wrong > takes it out of good advice into the realm of superstition.
Bullshit. Comparing floats by their representation is *generally* a bad idea because of portability issues. You don't know if IEEE754 is used to represent floats on the systems that your code is used on. You're hairsplitting: when I'd have said "in 99.9% of cases" you'd agree with me but since I said "always" you disagree. Don't lawyer out. Comparing binary representation of floats is a crappy idea. Even more so in the age of cloud computing where your code is executed on who knows which architecture where the exact same high level interpretation might lead to vastly different results. Not to mention high performance computing, where specialized FPUs can numerously be found which don't give a shit about IEEE754. Another thing why it's good to NEVER compare floats with regards to their binary representation: Do you exactly know how your FPU is configured by your operating system. Do you know that your FPUs on a multiprocessor system are configured all identically with regards to 754? Rounding modes, etc? Just don't fall in the pit. Don't compare floats via equals. >> when x < x -> False > > Because not all types are ordered: > > py> x = 1+3j > py> x < x > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > TypeError: unorderable types: complex() < complex() Oh, so then you also don't want refelexivity of equals, I think. Because, obviously, not all types support comparison for equality: #!/usr/bin/python3 class Yeah(object): def __eq__(self, other): raise TypeError("Booya") Yeah() == Yeah() You cherrypick your logic and hairsplit in your reasoning. It's not consistent. Cheers, Johannes -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht öffentlich! Ah, der neueste und bis heute genialste Streich unsere großen Kosmologen: Die Geheim-Vorhersage. - Karl Kaos über Rüdiger Thomas in dsa <hidbv3$om2$1...@speranza.aioe.org> -- https://mail.python.org/mailman/listinfo/python-list