|
|
|
|
|
by throwaway313373
594 days ago
|
|
I can think of some more interesting examples when it violates intuition gained from mathematical notation. When looking at `a == b == c` we naturally assume that not only `a == b` and `b == c` but also `a == c` because equality is assumed to be transitive. The problem is that in Python we can make `==` operator to do literally whatever we want, so in Python `==` doesn't have to be transitive. You may argue that no reasonable person would define equality in such way that is not transitive. To which I would reply that approximate comparison of floating point numbers looks perfectly reasonable to me. EPSILON = 10**-9
class Foo:
def __eq__(self, other):
return other.bar - EPSILON <= self.bar <= other.bar + EPSILON
|
|