I make a set {1, -1}, and then test membership of the elements as ints, floats, mpf's and mpc's. I expect all of these membership tests to return True.
>>> import mpmath
>>> s = {1, -1}
>>> 1 in s
True
>>> -1 in s
True
>>> 1.0 in s
True
>>> -1.0 in s
True
>>> mpmath.mpf(1) in s
True
>>> mpmath.mpf(-1) in s
True
>>> mpmath.mpc(1) in s
True
>>> mpmath.mpc(-1) in s
False # <---- what?
I didn't expect that last False; it seems inconsistent.
The same thing happens if a dict is used instead of a set.
Alternatively, we can look at the hash values:
>>> hash(1), hash(1.0), hash(mpmath.mpf(1)), hash(mpmath.mpc(1))
(1, 1, 1, 1)
>>> hash(-1), hash(-1.0), hash(mpmath.mpf(-1)), hash(mpmath.mpc(-1))
(-2, -2, -2, 6)
That last 6 looks like an anomaly. Shouldn't it be -2 like the others next to it?
I make a set
{1, -1}, and then test membership of the elements as ints, floats, mpf's and mpc's. I expect all of these membership tests to return True.I didn't expect that last
False; it seems inconsistent.The same thing happens if a dict is used instead of a set.
Alternatively, we can look at the hash values:
That last 6 looks like an anomaly. Shouldn't it be -2 like the others next to it?