Bizarre arithmetic results
Robert Kern
robert.kern at gmail.com
Thu Feb 11 10:55:30 EST 2010
On 2010-02-11 06:31 AM, Shashwat Anand wrote:
> Do you really believe that -0.1 ** 0.1 is a valid computational problem
> ? Can you raise a negative number to a fractional power ?
> Output on my console (python 2.6)
>
> >>> -.1 ** .1
> -0.79432823472428149
> >>> a,b = -.1,.1
> >>> a**b
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> ValueError: negative number cannot be raised to a fractional power
> >>> -abs(a**b)
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> ValueError: negative number cannot be raised to a fractional power
>
> There is a little issue here that '>>> -.1 ** .1' should give you error
> message. That is it.
No, fractional powers of negative numbers are perfectly valid mathematically.
The result is a complex number. In Python 3 (what the OP is using), this has
been implemented, but not in Python 2.6.
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the Python-list
mailing list