Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!gamma!epsilon!zeta!sabre!petrus!bellcore!decvax!decwrl!pyramid!pesnta!hplabs!qantel!lll-lcc!lll-crg!seismo!brl-adm!brl-smoke!smoke!cottrell@NBS-VMS.ARPA From: cottrell@NBS-VMS.ARPA (COTTRELL, JAMES) Newsgroups: net.lang.c Subject: Integer Division Message-ID: <1510@brl-smoke.ARPA> Date: Tue, 4-Mar-86 16:32:54 EST Article-I.D.: brl-smok.1510 Posted: Tue Mar 4 16:32:54 1986 Date-Received: Sat, 8-Mar-86 22:22:24 EST Sender: news@brl-smoke.ARPA Lines: 24 /* > > Is there someone out there who *wants* a/b to round towards 0 (for reasons > > that say that is the desired result)? I asked that before and have not seen > > any affirmatives. > > > > ucbvax!brahms!weemba Matthew P Wiener/UCB Math Dept/Berkeley CA 94720 > > I do! Mainly because I want the absolute value of (-a)/b to equal the absolute > value of a/b. > -- > -Pete Zakel (..!{hplabs,amd,pyramid,ihnp4}!pesnta!valid!pete) Me too. Conceptually, `a/b' is `how many times does b go into a'? What is left over has the same sign as the dividend. It seems that most previously built computers truncate towards zero. Ironically, I also prefer that `a%b' be positive, so that the `%' operator is actually the `modulus' rather than the remainder. Thus we have the contradiction that `a != (a/b)*b + (a%b)' for all possible a & b. But, as previously noted, mostly we do `%' on positive integers. Of course, if b is a power of two, you can just `&' with `b - 1' to get the real modulus. jim cottrell@nbs */ ------