[issue8748] integer-to-complex comparisons give incorrect results

Meador Inge report at bugs.python.org
Wed May 19 15:14:02 CEST 2010


Meador Inge <meadori at gmail.com> added the comment:

> For a complex number z and an integer i, 'z == i' should be exactly 
> equivalent to 'z.real == i and z.imag == 0.0'.

Like you mentioned before a lot of care is taken in 'floatobject.c' to ensure that the comparison is robust.  Would it be a good approach to leverage that work?

I have attached a patch with that idea.  If it seems reasonable, then I can clean it up and add more tests.  I created the patch for py3k.  I think the 2.x changes will be slightly different due to the coercion aspects.

One of the unit tests ('test_complex.test_richcompare') explicitly checks for the overflow.  However, the approach of just having the comparison return 'False' in these cases is more robust.  Is there any use case for explicitly notifying of overflow with comparisons?  It seems like more of an implementation artifact to me...

----------
keywords: +patch
nosy: +minge
Added file: http://bugs.python.org/file17402/issue-8748.patch

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


More information about the Python-bugs-list mailing list