Integer division

Kenneth Almquist ka at hropus.UUCP
Tue Feb 11 17:46:56 AEST 1986


> Perhaps K&R thought that the performance penalty of implementing a
> consistent modulus (or divide) was not justified, since negative
> integers are rarely encountered in "C" [this comment cannot be traced
> to K&R.]  However, this performance penalty can be avoided simply by
> declaring unsigned integers as "unsigned int".

On the VAX, the unsigned remainder function is implemented as a
subroutine call.  The standard divide instruction cannot be used
because the divide instruction does not work on unsigned integers.

In Ada, division truncates towards zero, and there are separate
remainder and modulo operators.  The % operator in C is a remainder
operator; we could have a new operator %% for modulo.  (On the other
hand, maybe not.  We don't want C to get as large as Ada!)
				Kenneth Almquist
				ihnp4!houxm!hropus!ka	(official name)
				ihnp4!opus!ka		(shorter path)



More information about the Comp.lang.c mailing list