Integer division

Doug Gwyn gwyn at brl-smoke.ARPA
Thu Feb 6 09:41:50 AEST 1986


What I would like is for the language to provide a notation
for obtaining BOTH the quotient and the remainder of an
integer division in a single operation.  Too often I need
both and have to go through extra overhead to get them
(many computers compute both parts at the same time).

(I would also like to get both the sine and the cosine of
an angle in a single operation with reduced overhead, but
that seems much less feasible.)

This % vs. Mod debate is rather silly.  C's % operator is
NOT repeat NOT intended to be a modulo operator, although
people often use it that way for positive operands.  All
reasonable mathematicians agree on what the definition of
	a mod b
is for positive b and negative a.  That should not be
confused with what the result of
	a % b
should be under similar circumstances.  C intentionally
hedges a bit on the meaning of % in such a case (which
makes that a generally inadvisable situation to allow to
arise in one's C code).



More information about the Comp.lang.c mailing list