proposed language change to int/int==float (was: PEP0238 lament)

Marcin 'Qrczak' Kowalczyk qrczak at
Mon Jul 30 02:30:49 EDT 2001

Mon, 30 Jul 2001 05:30:37 GMT, Bengt Richter <bokr at> pisze:

>>result depends on the value of the argument (x**y returns at least
>>a float when y is a rational, but may return an integer when y is
>    ^^^^^-inexact           vs.            exact--^^^^^^^
>>a nonnegative integer) and turns some TypeErrors into ValueErrors
> Actually, with rationals, could't you return the inverse rational
> for negative y integers ;-)

Surely rational**negative_integer should return a rational - this case
"lies between" cases considered in this example.

The reason of the unusual behavior of ** is simple: there are about
four operations artificially folded into one operator.

It could be done because it happens that they give equal results on
equal inputs, and it's commonly done in mathematics and programming

These operations are the following (generally each time it's statically
known which is meant):

- Raising an element of a ring (or even associative group) to a
  nonnegative integer exponent. It means: multiply the given number
  of times (with 0 giving the unit).

- Raising an element of a field to an integer exponent. If the
  exponent is negative, the number must be non-zero. It means: if
  the exponent is nonnegative, multiply the given number of times,
  otherwise multiply inverses.

- Raising a real or complex number to a rational exponent. If the
  exponent is negative, the number must be non-zero. If we are not
  considering complexes and the exponent has an even denominator,
  the number must be nonnegative. The meaning is well known, I won't
  repeat the full definition.

- Raising a positive real number to a real exponent, or raising
  a complex number to a complex exponent. It means: x**y ==
  exp(y*log(x)), for suitably overloaded exp and log.

Each time you give a more general exponent, you demand more from the
domain of the base, and sometimes previously valid results no longer
exist (e.g. (-1)**(1/3) is defined, but (-1)**float(1/3) is not).

 __("<  Marcin Kowalczyk * qrczak at
  ^^                      SYGNATURA ZASTĘPCZA

More information about the Python-list mailing list