]> granicus.if.org Git - python/commitdiff
Closes SF bug #634069 reporting the docs on the ** operator were out
authorRaymond Hettinger <python@rcn.com>
Fri, 8 Nov 2002 05:30:23 +0000 (05:30 +0000)
committerRaymond Hettinger <python@rcn.com>
Fri, 8 Nov 2002 05:30:23 +0000 (05:30 +0000)
of date and did not reflect the current CPython implementation.

Doc/ref/ref5.tex

index f554ab49d18b549264676fcdc74050caf9d886a3..af1fa198f1458919058b837b6f19e3bc67de4118 100644 (file)
@@ -599,10 +599,20 @@ The power operator has the same semantics as the built-in
 \function{pow()} function, when called with two arguments: it yields
 its left argument raised to the power of its right argument.  The
 numeric arguments are first converted to a common type.  The result
-type is that of the arguments after coercion; if the result is not
-expressible in that type (as in raising an integer to a negative
-power, or a negative floating point number to a broken power), a
-\exception{TypeError} exception is raised.
+type is that of the arguments after coercion.
+
+With mixed operand types, the coercion rules for binary arithmetic
+operators apply. For int and long int operands, the result has the
+same type as the operands (after coercion) unless the second argument
+is negative; in that case, all arguments are converted to float and a
+float result is delivered. For example, \code{10**2} returns \code{100},
+but \code{10**-2} returns \code{0.01}. (This last feature was added in
+Python 2.2. In Python 2.1 and before, if both arguments were of integer
+types and the second argument was negative, an exception was raised).
+
+Raising \code{0.0} to a negative power results in a
+\exception{ZeroDivisionError}.  Raising a negative number to a
+fractional power results in a \exception{ValueError}.
 
 
 \section{Unary arithmetic operations \label{unary}}