Python 2.x breaks cmp() (was Re: A suspected bug)
ssthapa at classes.cs.uchicago.edu
ssthapa at classes.cs.uchicago.edu
Tue Feb 20 12:53:50 EST 2001
Aahz Maruch <aahz at panix.com> wrote:
>>>>> L=[1j, 2j]
>>>>> L.sort()
>>Traceback (most recent call last):
>> File "<stdin>", line 1, in ?
>>TypeError: cannot compare complex numbers using <, <=, >, >=
>>>>>
>
>Is there any chance this can be treated as a bug and fixed for the
>release of 2.1? Alternatively, given that we're already breaking code
>with the change in the way complex numbers are handled, should cmp() now
>raise an exception *every* time the type/class differs?
If you are referring to the comparision of complex numbers, I'm not
sure how the ordering would be done. For example consider 1 and 1j,
they have the same magnitude so mathematically speaking there is no
way to consistently order them like the real numbers where magnitude
is a more useful measure. IIRC, for any given magnitude n there are an
infinite number of complex numbers with that magnitude, namely all n*e^(ix)
for real x.
--
----------------------------------------------------------------------------
|
Suchandra Thapa | "There are only two kinds of math .
s-thapa-11 at NOSPAMalumni.uchicago.edu | books. Those you cannot read beyond
| the first sentence, and those you
| can not read beyond the first page."
| -C.N. Yang
----------------------------------------------------------------------------
More information about the Python-list
mailing list