Problem with complex numbers

Matthias Götz matthias.goetz.23 at
Sat Mar 22 22:37:45 CET 2008

Hello python fans,

I have a small problem using python and complex math.

The pow(complex,complex) function in the windows python version doesn't have
the same semantic as the source version.

(I have downloaded :


   Python 2.5.2 compressed source
Unix or OS X compile)
   - Python 2.5.2 Windows


If found in

    def __pow__(self, n, z=None):
        if z is not None:
            raise TypeError, 'Complex does not support ternary pow()'
        if IsComplex(n):
                if raise TypeError, 'Complex to the Complex power'
                else: return exp(math.log(*n)
            n =
        r = pow(self.abs(), n)
        phi = n*self.angle()
        return Complex(math.cos(phi)*r, math.sin(phi)*r)

which mean for example if i calculate z1 power z2 (z1,z2 are complex
and z1 and z2 has imaginary parts not equals zero,
i must get an TypeError. Is that right?

But i tried that in the IDLE python shell by doing this

>>> z1=complex(1,2)
>>> z2=complex(2,3)
>>> z1**z2

and this is everything unlike an TypeError.

So if somebody can help me, it would be nice. Thanks.


(Sorry for bad english, I'am german)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list