[Python-ideas] complex number and fractional exponent
Oscar Benjamin
oscar.j.benjamin at gmail.com
Sat Jan 26 22:22:22 CET 2013
On 26 January 2013 19:09, Terry Reedy <tjreedy at udel.edu> wrote:
>
> For sqrt, one also has a choice and always has since complexes were added.
>>>> import math, cmath
>>>> math.sqrt(-1)
>
> Traceback (most recent call last):
> File "<pyshell#1>", line 1, in <module>
> math.sqrt(-1)
> ValueError: math domain error
>>>> cmath.sqrt(-1)
> 1j
Why does cmath.sqrt give a different value from the __pow__ version?
~$ python3
Python 3.2.3 (default, Oct 19 2012, 19:53:16)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cmath
>>> cmath.sqrt(-1)
1j
>>> (-1) ** .5
(6.123031769111886e-17+1j)
Oscar
More information about the Python-ideas
mailing list