[Python-Dev] compex numbers (was Floor Division)
Nick Maclaren
nmm1 at cus.cam.ac.uk
Tue Jan 23 21:39:53 CET 2007
"Jim Jewett" <jimjjewett at gmail.com> wrote:
> Tim Peters wrote:
>
> > complex_new() ends with:
>
> > cr.real -= ci.imag;
> > cr.imag += ci.real;
>
> > and I have no idea what that thinks it's doing. Surely this isn't intended?!
> :
>
> I think it is. python.org/sf/1642844 adds comments to make it less unclear.
Agreed.
>
> If "real" and "imag" are themselves complex numbers, then normalizing
> the result will move the imaginary portion of the "real" vector into
> the imaginary part and vice versa.
Not really. What it does is to make complex(a,b) exactly equivalent
to a+1j*b. For example:
>>> a = 1+2j
>>> b = 3+4j
>>> complex(a)
(1+2j)
>>> b*1j
(-4+3j)
>>> complex(a,b)
(-3+5j)
> Note that changing this (to discard the imaginary parts) would break
> passing complex numbers to their own constructor.
Eh? Now, I am baffled. There are several ways of changing it, all
of which would turn one bizarre behaviour into another - or would
raise an exception. Personally, I would do the following:
complex(a) would permit a to be complex.
complex(a,b) would raise an exception if either a or b were complex.
But chacun a son gout (accents omitted).
Regards,
Nick Maclaren,
University of Cambridge Computing Service,
New Museums Site, Pembroke Street, Cambridge CB2 3QH, England.
Email: nmm1 at cam.ac.uk
Tel.: +44 1223 334761 Fax: +44 1223 334679
More information about the Python-Dev
mailing list