On Thu, May 6, 2010 at 6:33 PM, Xavier Ho <cont...@xavierho.com> wrote: > On Fri, May 7, 2010 at 11:13 AM, Chris Rebert <pyid...@rebertia.com> wrote: >> On Thu, May 6, 2010 at 5:43 PM, Mathias Panzenböck >> <grosser.meister.mo...@gmx.net> wrote: >> > Shouldn't by mathematical definition -x // y be the same as -(x // y)? >> > I think this rather odd. Is there any deeper reason to this behaviour? I >> > guess changing this will break a lot of code, but why does it behave >> > like >> > this? >> >> I would suppose it's what programmers have found more >> useful/intuitive. Most programmers aren't number theorists. > > Yeah, I was stinged by that before, too. I really don't find it intuitive at > all - to keep the modulos remainer equal, you lose on negations and possibly > integer equality. Ah well, too bad I didn't invent Python. =].
Personally, I find the following the most unintuitive: divmod(-11, 3) == (-4, 1) So, we overshoot -11 and then add 1 to go back to the right place? That violates my intuitive thought that abs((n//d)*d) <= abs(n) ought to hold. Cheers, Chris -- This is why we don't rely on intuition alone. http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list