[Python-ideas] math module and complex numbers

Mark Dickinson dickinsm at gmail.com
Wed Mar 11 15:28:45 CET 2009


On Wed, Mar 11, 2009 at 1:31 PM, Oleg Broytmann <phd at phd.pp.ru> wrote:
> numbers. The distinction between functions which support complex numbers
> and those which don't is made since most users do not want to learn quite
> as much mathematics as required to understand complex numbers. Receiving an
> exception instead of a complex result allows earlier detection"

Furthermore, even those users who *do* understand complex numbers don't
always want sqrt(-1) to return 1j.  I find the math/cmath duality useful.

Mark

>>> from cmath import sqrt
>>> sqrt(-complex(1))
-1j
>>> sqrt(complex(-1))
1j



More information about the Python-ideas mailing list