Integer division and remainder

Paul Rubin phr-n2001 at nightsong.com
Wed Aug 15 08:46:08 EDT 2001


"Tim Peters" <tim.one at home.com> writes:
> WRT Python, the decision to do flooring integer division was very
> deliberate, and not something Guido (or I -- since I pushed him this way,
> it's my fault <wink>) has ever had cause to regret.  We simply regret that
> division returns an integer at all(!).

I thought of doing it that way in gawk (I wrote the original gawk
interpreter) but wimped out and decided it was best to have two
separate operators (that never got implemented).  If it's working
out in python that's great.

I think C99 made a mistake in specifying it one way or the other.  C
doesn't have the same goals as python.  Languages like python should
specify these things precisely.  Languages like C should leave more
things up to the hardware.

I don't know of any computers whose native division instructions do
flooring integer division like python does.  

I also notice that math.fmod (-3, 2) = -1.0, so now there's this weird
inconsistency between integer % and math.fmod.  I don't know offhand
what IEEE 796 says to do with fmod.

Finally I see that they added a // operation (floor division) to
Python 2.2 and it looks like there's more changes like that in the pipeline.



More information about the Python-list mailing list