Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!bellcore!decvax!decwrl!amdcad!lll-crg!seismo!utah-cs!utah-gr!thomas From: thomas@utah-gr.UUCP (Spencer W. Thomas) Newsgroups: net.lang.c,net.arch Subject: Re: Integer division Message-ID: <1666@utah-gr.UUCP> Date: Fri, 31-Jan-86 13:23:41 EST Article-I.D.: utah-gr.1666 Posted: Fri Jan 31 13:23:41 1986 Date-Received: Sat, 1-Feb-86 21:37:55 EST References: <332@ism780c.UUCP> <11603@ucbvax.BERKELEY.EDU> <11610@ucbvax.BERKELEY.EDU> <11612@ucbvax.BERKELEY.EDU> Reply-To: thomas@utah-gr.UUCP (Spencer W. Thomas) Distribution: net Organization: Univ of Utah CS Dept Lines: 15 Xref: watmath net.lang.c:7723 net.arch:2451 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. If you really want MOD, here it is: mod(a,b) { return (( a % b ) + b) % b; } -- =Spencer ({ihnp4,decvax}!utah-cs!thomas, thomas@utah-cs.ARPA)