[New-bugs-announce] [issue8748] integer-to-complex comparisons give incorrect results

Mark Dickinson report at bugs.python.org
Tue May 18 12:37:16 CEST 2010


New submission from Mark Dickinson <dickinsm at gmail.com>:

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'.

----------
assignee: mark.dickinson
components: Interpreter Core
messages: 105963
nosy: mark.dickinson
priority: high
severity: normal
status: open
title: integer-to-complex comparisons give incorrect results
type: behavior
versions: Python 2.6, Python 2.7, Python 3.1, Python 3.2

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue8748>
_______________________________________


More information about the New-bugs-announce mailing list