Bizarre arithmetic results

Mark Dickinson dickinsm at gmail.com
Thu Feb 11 09:21:57 EST 2010


On Feb 11, 1:38 pm, Duncan Booth <duncan.bo... at invalid.invalid> wrote:
> Tim Chase <python.l... at tim.thechases.com> wrote:
> > But perhaps Py3 changes evaluation, returning an complex number.
>
> Yes, the change is documented athttp://docs.python.org/3.1/reference/expressions.html#the-power-operator
>
> If it is in any of the "What's new in Python x.xx" documents or in a PEP
> somewhere I haven't spotted it.

Not in the 'what's new' documents, as far as I can tell, but this
change was introduced as part of implementing PEP 3141.

http://www.python.org/dev/peps/pep-3141/

Here's an extract from the PEP, describing the 'Complex' abstract base
class:


class Complex(Number):
    """Complex defines the operations that work on the builtin complex
type.

    In short, those are: conversion to complex, bool(), .real, .imag,
    +, -, *, /, **, abs(), .conjugate(), ==, and !=.

    If it is given heterogenous arguments, and doesn't have special
    knowledge about them, it should fall back to the builtin complex
    type as described below.
    """

    <snip lots of other abstractmethods here>

    @abstractmethod
    def __pow__(self, exponent):
        """a**b; should promote to float or complex when necessary."""
        raise NotImplementedError


--
Mark



More information about the Python-list mailing list