[Python-Dev] pyc files, constant folding and borderline portability issues

Fredrik Johansson fredrik.johansson at gmail.com
Tue Apr 7 21:09:26 CEST 2009


On Tue, Apr 7, 2009 at 8:59 PM, Alexandru Moșoi <brtzsnr at gmail.com> wrote:

> Not necessarily. For example C/C++ doesn't define the order of the
> operations inside an expression (and AFAIK neither Python) and
> therefore folding 2 * 3 is OK whether b is an integer or an arbitrary
> object with mul operator overloaded. Moreover one would expect * to be
> associative and commutative (take a look at Python strings); if a * 2
> * 3 returns a different result from a * 6 I will find it very
> surprising and probably reject such code.

Multiplication is not associative for floats:

>>> a = 0.1
>>> a*3*5
1.5000000000000002
>>> a*(3*5)
1.5

Fredrik


More information about the Python-Dev mailing list