Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0da7f39

Browse files
committed
Closes SF bug #634069 reporting the docs on the ** operator were out
of date and did not reflect the current CPython implementation.
1 parent 0ec1ddc commit 0da7f39

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

Doc/ref/ref5.tex

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -599,10 +599,20 @@ \section{The power operator\label{power}}
599599
\function{pow()} function, when called with two arguments: it yields
600600
its left argument raised to the power of its right argument. The
601601
numeric arguments are first converted to a common type. The result
602-
type is that of the arguments after coercion; if the result is not
603-
expressible in that type (as in raising an integer to a negative
604-
power, or a negative floating point number to a broken power), a
605-
\exception{TypeError} exception is raised.
602+
type is that of the arguments after coercion.
603+
604+
With mixed operand types, the coercion rules for binary arithmetic
605+
operators apply. For int and long int operands, the result has the
606+
same type as the operands (after coercion) unless the second argument
607+
is negative; in that case, all arguments are converted to float and a
608+
float result is delivered. For example, \code{10**2} returns \code{100},
609+
but \code{10**-2} returns \code{0.01}. (This last feature was added in
610+
Python 2.2. In Python 2.1 and before, if both arguments were of integer
611+
types and the second argument was negative, an exception was raised).
612+
613+
Raising \code{0.0} to a negative power results in a
614+
\exception{ZeroDivisionError}. Raising a negative number to a
615+
fractional power results in a \exception{ValueError}.
606616
607617
608618
\section{Unary arithmetic operations \label{unary}}

0 commit comments

Comments
 (0)