We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
pow
**
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The documentation of the pow function currently states:
The two-argument form pow(base, exp) is equivalent to using the power operator: base**exp.
pow(base, exp)
base**exp
This is incorrect for negative base with exponents between 0 and 1 (both exclusive). E.g.:
base
>>> pow(-9, 0.5) (1.8369701987210297e-16+3j) >>> -9 ** 0.5 -3.0
(Tested for Python 3.8.2 and 3.10.6.)
While pow returns a complex value, ** simply returns the negative square root of the absolute value of base.
Note that this is only the difference in behavior that I observed so far. Issue #60200 suggests there might be more.
The text was updated successfully, but these errors were encountered:
Hello! There's no bug. ** has a higher precedence than the negation operator -. So, your expression calculates as -(9 ** 0.5). FYI: https://docs.python.org/3/reference/expressions.html#operator-precedence
-
-(9 ** 0.5)
Sorry, something went wrong.
I see. Thank you!
Maybe in Python 4, this could be invalid syntax to protect against this footgun. I mean, JS made this invalid syntax.
> -9 ** 0.5 -9 ** 0.5 ^^^^^ SyntaxError: Unary operator used immediately before exponentiation expression. Parenthesis must be used to disambiguate operator precedence
No branches or pull requests
Documentation
The documentation of the
pow
function currently states:This is incorrect for negative
base
with exponents between 0 and 1 (both exclusive). E.g.:(Tested for Python 3.8.2 and 3.10.6.)
While
pow
returns a complex value,**
simply returns the negative square root of the absolute value ofbase
.Note that this is only the difference in behavior that I observed so far. Issue #60200 suggests there might be more.
The text was updated successfully, but these errors were encountered: