Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.3 4.3bsd-beta 6/6/85; site ucbvax.BERKELEY.EDU Path: utzoo!watmath!clyde!burl!ulysses!bellcore!decvax!decwrl!ucbvax!brahms!weemba From: weemba@brahms.BERKELEY.EDU (Matthew P. Wiener) Newsgroups: net.lang.c,net.arch Subject: Re: Integer division Message-ID: <11652@ucbvax.BERKELEY.EDU> Date: Sat, 1-Feb-86 08:00:34 EST Article-I.D.: ucbvax.11652 Posted: Sat Feb 1 08:00:34 1986 Date-Received: Sun, 2-Feb-86 05:44:34 EST References: <332@ism780c.UUCP> <11603@ucbvax.BERKELEY.EDU> <11610@ucbvax.BERKELEY.EDU> <11612@ucbvax.BERKELEY.EDU> <1666@utah-gr.UUCP> Sender: usenet@ucbvax.BERKELEY.EDU Reply-To: weemba@brahms.UUCP (Matthew P. Wiener) Distribution: net Organization: University of California, Berkeley Lines: 54 Xref: watmath net.lang.c:7727 net.arch:2454 In article <1666@utah-gr.UUCP> thomas@utah-gr.UUCP (Spencer W. Thomas) writes: >There is of course, always another way to look at it. The '%' operator >is not defined to be MOD, it is defined such that > (a/b)*b + a%b = a >In other words, it is the REMAINDER upon dividing a by b. Now, if you >want a%b to always be positive, you must then have > (-a)/b != -(a/b) >which, I think you will agree, is much worse. In previous articles, I and Gene Smith, both mathematicians, have stated our disapproval of defining % to be sometimes + and sometimes -. We did not get around to stating our opinions of the two identities involved, so here's mine. (a/b)*b + a%b == a This identity is clearly needed. It enables one to go back and forth between / and % in a consistent way, irregardless of whether % is MOD. Indeed, among mathematicians, the official definition of quotient and remainder for a over b (a,b integers with b>0) is to find the unique integer values of q and r such that a==b*q+r and 0<=r0 in the official mathematical definition. I really have no idea what one should do with b<0 in actual implementations. I have never seen it come up in or out of mathematics. Indeed, it perhaps seems preferable to generate some sort of arithmetic fault here. (Similarly there are rare cases where you want 3./0. to NOT cause a divide by zero fault, but you keep the fault because programmer error is the more likely explanation for 3./0..) But I am straying. (Of course, these comments about division only refer to integer division.) ----------------------------------------------------------------------------- Sorry if we seemed a little heavy handed last time. They've always seemed like defects that we users have to program around, and with no chance of ever changing, burned into all programming languages forever because--before I was even born!--someone chose the wrong convention. (Physicists sometimes dream of a world were the electron has a *positive* charge; if only we could go back in time and tell Ben Franklin to try the other convention; believe us, Ben, it makes a difference; etc.; sigh) Suddenly we get attached to the network and discover that maybe there is a way--why someone out there even ASKED us mathematicians what we thought! (Thanks!) We are both ex-Fortran programmers, and feel C and C++ are the wave of the future among scientific programmers. Now to convince the others.... (You powers that be might want to help!) ucbvax!brahms!weemba Matthew P Wiener/UCB Math Dept/Berkeley CA 94720