[Python-Dev] compex numbers (was Floor Division) (original) (raw)
Jim Jewett jimjjewett at gmail.com
Tue Jan 23 20:47:26 CET 2007
- Previous message: [Python-Dev] Problem with signals in a single threaded application
- Next message: [Python-Dev] compex numbers (was Floor Division)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Tim Peters wrote:
complexnew() 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.
>>> complex(complex(1.0, 2.0), complex(10.0, 20.0)) (-19+12j)
WTF?
>>> help(complex)
Help on class complex in module __builtin__:
class complex(object)
| complex(real[, imag]) -> complex number
|
| Create a complex number from a real part and an optional imaginary part.
| This is equivalent to (real + imag*1j) where imag defaults to 0.
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.
Note that changing this (to discard the imaginary parts) would break passing complex numbers to their own constructor.
>>> a=complex(1,2)
>>> b=complex(a)
>>> a==b
True
-jJ
- Previous message: [Python-Dev] Problem with signals in a single threaded application
- Next message: [Python-Dev] compex numbers (was Floor Division)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]