This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mark.dickinson
Recipients mark.dickinson
Date 2010-05-18.10:37:12
SpamBayes Score 0.0013876715
Marked as misclassified No
Message-id <1274179036.3.0.754840788913.issue8748@psf.upfronthosting.co.za>
In-reply-to
Content
I've just discovered that integer-to-complex comparisons are broken, in all versions of Python that I've tested.  It looks as though the integer is first converted to a complex number, and then the two complex numbers are compared.  That's not correct, and it's contrary to what happens for floats, where there's special handling in place to make sure that exact values are compared.  This leads to loss of transitivity of equality:

>>> n = 2**53+1
[51529 refs]
>>> float(n) == complex(n)  # expect True
True
[51531 refs]
>>> n == float(n)           # expect False
False
[51531 refs]
>>> n == complex(n)         # expect False, but Python returns True
True
[51531 refs]

Apparently the SAGE folks noticed this some time ago, but AFAICT didn't report it as a bug. See http://www.mail-archive.com/sage-devel@googlegroups.com/msg20891.html

For a complex number z and an integer i, 'z == i' should be exactly equivalent to 'z.real == i and z.imag == 0.0'.
History
Date User Action Args
2010-05-18 10:37:16mark.dickinsonsetrecipients: + mark.dickinson
2010-05-18 10:37:16mark.dickinsonsetmessageid: <1274179036.3.0.754840788913.issue8748@psf.upfronthosting.co.za>
2010-05-18 10:37:14mark.dickinsonlinkissue8748 messages
2010-05-18 10:37:12mark.dickinsoncreate