Bizarre arithmetic results

Christian Heimes lists at cheimes.de
Thu Feb 11 07:33:37 EST 2010


Terrence Cole wrote:
>>>> -0.1 ** 0.1
> -0.7943282347242815
>>>> a = -0.1; b = 0.1
>>>> a ** b
> (0.7554510437117542+0.2454609236416552j)
>>>> -abs(a ** b)
> -0.7943282347242815
> 
> Why does the literal version return the signed magnitude and the
> variable version return a complex?

The binary power operator has a higher precedence than the unary
negative operator. -0.1 ** 0.1 is equal to -(0.1**0.1)

Christian




More information about the Python-list mailing list