Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site ucla-cs.ARPA Path: utzoo!watmath!clyde!cbosgd!ukma!psuvm.bitnet!psuvax1!burdvax!sdcrdcf!ucla-cs!jimc From: jimc@ucla-cs.UUCP Newsgroups: net.lang.c,net.arch Subject: Re: Integer division Message-ID: <8966@ucla-cs.ARPA> Date: Thu, 13-Feb-86 19:55:59 EST Article-I.D.: ucla-cs.8966 Posted: Thu Feb 13 19:55:59 1986 Date-Received: Sun, 16-Feb-86 04:22:50 EST References: <332@ism780c.UUCP> <11603@ucbvax.BERKELEY.EDU> <11610@ucbvax.BERKELEY.EDU> <561@jplgodo.UUCP> Reply-To: jimc@ucla-cs.UUCP (Jim Carter) Distribution: net Organization: UCLA Computer Science Department Lines: 27 Xref: watmath net.lang.c:7862 net.arch:2523 In article <561@jplgodo.UUCP> steve@jplgodo.UUCP (Steve Schlaifer x3171 156/224) writes: >If you think of % as returning the *mathematical* remainder of a/b then >it should return a value >=0. On the other hand, to be consistent with this >view, the quotient operator (/) will also have to be modified to preserve >the formulae > > b=qa+r (0<=r q=b/a > >i.e. (-3)/2 must be -2 if (-3)%2 is 1. But this then means that (|a|)/b is not >the same as |a/b| for a<0. Maybe *An Angry Number Theorist* wants this, but... > Right on! Invariably when I integer-divide negative numbers I have to do fancy coding to cause (-3)/2 to come out -2 rather than -1. I would very much like to see the quotient of *signed* integers come out this way auto- matically. However, most hardware doesn't cooperate, necessitating extra compiled code. I hope the compiler would have a separate, more efficient code macro for the unsigned case, so that users concerned with efficiency and knowing about their hardware could avoid useless overhead by declaring unsigned ints. This kind of efficient compilation would be helped if all int constants were automatically unsigned. In other words, the compiler would interpret -5 as (unary negate operator)(cast to signed)(unsigned int ={5}). James F. Carter (213) 206-1306 UCLA-SEASnet; 2567 Boelter Hall; 405 Hilgard Ave.; Los Angeles, CA 90024 UUCP:...!{ihnp4,ucbvax,{hao!cepu}}!ucla-cs!jimc ARPA:jimc@locus.UCLA.EDU