why no arg, abs methods for comlex type?

Terry Reedy tjreedy at udel.edu
Fri Aug 5 10:57:17 EDT 2005


"Daniel Schüle" <uval at rz.uni-karlsruhe.de> wrote in message 
news:dcvqc2$8oi$1 at news2.rz.uni-karlsruhe.de...
> I wonder why there are no methods like arg, abs

> well one can use
> c = 1+1j
> abs(c)
>
> In my opinion it would also be nice to have the
> possibility to write it as
> c.abs()
> it looks more OO

Python is object based but not rigidly OO in syntax or looks.  This is an 
intentional design decision.  Not being gratuitiously redundant is another.

> unfortunately there is no arg method to get the angle
> of the complex number

I agree that this is a deficiency.  I would think .angle() should be a 
no-param method like .conjugate(), though its internal implementation would 
need access to the appropriate cmath functions.  I think returning radians 
might be enough though.  You could submit to the SourceForge tracker a RFE 
(Request For Enhancement) if not a patch.

> I would also like to see some more functions to make
> calculations with complex number more convenient
> e.g.
> c = 27
> c.pow(numerator = 1, denominator = 3,
>       mode = cmath.EULER, angle_mode = cmath.GRAD)
> -> ((3,0), (3,120), (3,240))

Wanting all roots is fairly specialized.  sqrt(4) is 2, not (2, -2).

> what do you think about it?
> maybe there exists some proposals aiming this goal?

Have you looked for complex math functions in numpy, numarray, scipy or 
similar packages?  It is possible that a cmath2 module, written in Python, 
could be useful.

Terry J. Reedy







More information about the Python-list mailing list