On Numbers

Steve Holden steve at holdenweb.com
Wed Jan 18 13:25:31 CET 2006

Erik Max Francis wrote:
> 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
>>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
> Note that cmath.sqrt returns the expected complex result for 
> cmath.sqrt(-1.0).
  >>> import cmath
  >>> cmath.sqrt(-1)

Indeed. But even exponentiation can come respectably close:

  >>> (-1+0j)**0.5

Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC                     www.holdenweb.com
PyCon TX 2006                  www.python.org/pycon/

More information about the Python-list mailing list