[Python-Dev] Order of operations (was: PEP 238 - The // operator should truncate instead of floor)

Facundo Batista facundobatista at gmail.com
Wed Aug 29 19:32:46 CEST 2007


2007/8/29, "Martin v. Löwis" <martin at v.loewis.de>:

> It would have been good if you had indicated what result you had
> expected instead. I assume 0; to get 0, you have to write -(3/2)+3/2,
> or 0-3/2+3/2.

Wow, that caught me:

>>> -3/2+3/2
-1
>>> 0-3/2+3/2
0
>>>

I'm not talking about division here, just the fact that in the first
case, it was (-3) / 2 and not -(3/2).

It's a surprise to me, taking into account that

>>> -3**2
-9
>>> 0-3**2
-9

Here, the behavior is always the same: -(3**2).

Do you know why? Thanks!

-- 
.    Facundo

Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org/ar/


More information about the Python-Dev mailing list