Bizarre arithmetic results
dickinsm at gmail.com
Thu Feb 11 15:21:57 CET 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.
Here's an extract from the PEP, describing the 'Complex' abstract base
"""Complex defines the operations that work on the builtin complex
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>
def __pow__(self, exponent):
"""a**b; should promote to float or complex when necessary."""
More information about the Python-list