math.pow vs pow
Peter Otten
__peter__ at web.de
Fri Nov 28 07:43:12 EST 2003
Georgy Pruss wrote:
>
> "John J. Lee" <jjl at pobox.com> wrote in message
> news:87k75lmlru.fsf at pobox.com...
> | For some applications, getting a complex result means you've made a
> | mistake. And some people don't know what a complex number is, and
> | would rather have their teeth drilled than find out.
>
> Can you provide an example when pow with real arguments gives a complex
> result, please?
He could, if Python were not so reluctant:
>>> pow(-5,.5)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ValueError: negative number cannot be raised to a fractional power
Sad day for the dentist:-)
But:
>>> pow(complex(-5), .5)
(1.3691515264124976e-16+2.2360679774997898j)
>>> pow(-5, complex(.5))
(1.3691515264124976e-16+2.2360679774997898j)
as you might expect.
Peter
More information about the Python-list
mailing list