On Numbers
Erik Max Francis
max at alcyone.com
Wed Jan 18 06:50:52 EST 2006
Steven D'Aprano wrote:
> Perhaps you meant to write (-1)**0.5, in which case Python developers have
> a decision to make: should it assume real-valued maths unless explicitly
> told differently, and hence raise an exception, or coerce the result to
> complex?
>
> In this case, Python raises an exception, as it should, unless you
> explicitly uses complex numbers. That's the best behaviour for the
> majority of people: most people don't even know what complex numbers are,
> let alone want to deal with them in their code. Python, after all, is not
> Mathematica.
Note that cmath.sqrt returns the expected complex result for
cmath.sqrt(-1.0).
--
Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
Our purpose is to make the agony of decision-making so intense that
you can escape only by thinking. -- Fred W. Friendly
More information about the Python-list
mailing list