Integer division

Craig Hansen hansen at mips.UUCP
Thu Feb 6 03:59:38 AEST 1986


I assume that everyone else is as sick and tired of seeing this dead horse
beaten as I am, but I find a point still unstated.

Several people have asked for mathematical reasons for choosing integer
division with rounding to - infinity rather than zero.  I submit the
following:

   If you wish to compute an approximation to a/b
   to the NEAREST integer, when a/b is rounded to
   minus infinity, you can use (a+a+b)/(b+b).
   I can think of no expression except those
   that involve conditionals for which this can
   be done when a/b is rounded to zero.

Craig Hansen
MIPS Computer Systems
...decvax!decwrl!mips!hansen



More information about the Comp.lang.c mailing list