math.exp(complex)

David Eppstein eppstein at ics.uci.edu
Sun Sep 21 16:08:56 EDT 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)
(-1+1.2246467991473532e-16j)

So why not math.exp(complex)?

-- 
David Eppstein                      http://www.ics.uci.edu/~eppstein/
Univ. of California, Irvine, School of Information & Computer Science




More information about the Python-list mailing list