David Eppstein eppstein at
Sun Sep 21 22:08:56 CEST 2003

Why doesn't this work?

>>> import math
>>> math.exp(1j*math.pi)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: can't convert complex to float; use e.g. abs(z)

The expected answer, of course, is -1.

It does work if you do it like this:

>>> math.e**(1j*math.pi)

So why not math.exp(complex)?

David Eppstein            
Univ. of California, Irvine, School of Information & Computer Science

More information about the Python-list mailing list