Message105963
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'. |
|
Date |
User |
Action |
Args |
2010-05-18 10:37:16 | mark.dickinson | set | recipients:
+ mark.dickinson |
2010-05-18 10:37:16 | mark.dickinson | set | messageid: <1274179036.3.0.754840788913.issue8748@psf.upfronthosting.co.za> |
2010-05-18 10:37:14 | mark.dickinson | link | issue8748 messages |
2010-05-18 10:37:12 | mark.dickinson | create | |
|