On 10/21/2012 09:35 PM, Steven D'Aprano wrote:
so as far as I can tell, the only way you could accidentally get a
complex number without expecting one is by exponentiation, either by **
or the builtin pow. This includes square roots. Exponentiation isn't as
common as the basic four arithmetic operators, but it is hardly exotic.
Any time you have a non-integer power and a negative base, you will get
a complex number.
No, only via the builtin pow.
% python3
Python 3.3.0 (default, Sep 29 2012, 22:42:55)
[GCC 4.6.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import math
>>> pow(-1, 0.5)
(6.123031769111886e-17+1j)
>>> -1 ** 0.5
-1.0
>>> math.pow(-1, 0.5)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: math domain error
>>>
//arry/
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com