Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site hropus.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxt!houxm!hropus!ka From: ka@hropus.UUCP (Kenneth Almquist) Newsgroups: net.lang.c Subject: Re: Integer division Message-ID: <261@hropus.UUCP> Date: Tue, 11-Feb-86 02:46:56 EST Article-I.D.: hropus.261 Posted: Tue Feb 11 02:46:56 1986 Date-Received: Wed, 12-Feb-86 08:09:11 EST References: <11603@ucbvax.BERKELEY.EDU> <4917@alice.UUCP> <11671@ucbvax.BERKELEY.EDU> <731@abic.UUCP> Organization: Bell Labs, Holmdel, NJ Lines: 17 > 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)