Bizarre arithmetic results
Jussi Piitulainen
jpiitula at ling.helsinki.fi
Thu Feb 11 07:37:45 EST 2010
More information about the Python-list mailing list
Thu Feb 11 07:37:45 EST 2010
- Previous message (by thread): Bizarre arithmetic results
- Next message (by thread): Bizarre arithmetic results
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Terrence Cole writes: > Can someone explain to me what python is doing here? > > Python 3.1.1 (r311:74480, Feb 3 2010, 13:36:47) > [GCC 4.3.4] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> -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 minus sign is not part of the literal syntax. Python takes the expression as -(0.1 ** 0.1), the binary operator binding tighter than the unary. Try (-0.1) ** 0.1, and try a = 0.1, then -a ** 0.1.
- Previous message (by thread): Bizarre arithmetic results
- Next message (by thread): Bizarre arithmetic results
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list