Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site mmintl.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxt!houxm!whuxl!whuxlm!akgua!gatech!seismo!cmcl2!philabs!pwa-b!mmintl!franka From: franka@mmintl.UUCP (Frank Adams) Newsgroups: net.arch Subject: Re: Right shift vs. divide (change divide!) Message-ID: <1032@mmintl.UUCP> Date: Tue, 14-Jan-86 05:03:11 EST Article-I.D.: mmintl.1032 Posted: Tue Jan 14 05:03:11 1986 Date-Received: Fri, 17-Jan-86 06:15:36 EST References: <124000005@ima.UUCP> <4772@alice.UUCP> <1016@turtlevax.UUCP> <32@calgary.UUCP> <285@mips.UUCP> Reply-To: franka@mmintl.UUCP (Frank Adams) Organization: Multimate International, E. Hartford, CT Lines: 30 In article <285@mips.UUCP> hansen@mips.UUCP (Craig Hansen) writes: >So now we've seen every possible solution: ignore it, >fix arithmetic right shift, and now fix divide! > >There are indeed two consistent definitions of divide, >both of which satisfy the relation: > > x = (x / y) * y + (x % y) > >The two definitions basically amount to evaluating x/y >by (1) rounding toward -infinity and (2) rounding toward zero. >Each have their own advantages: There is another important definition, which is to round to the nearest integer. (This is subdivided by what one does with a fractional part of exactly one half.) Uses for the rounded quotient should be quite obvious. The remainder in this case is the remainder with the smallest possible absolute value. This is useful in a variety of number-theoretic applications; as a simple example, Euclid's algorithm will terminate faster using the least absolute remainder. I will note also that I fairly often want to do a division and round up instead of down. This is especially common when dealing with arrays whose first element is 1, not 0. Frank Adams ihpn4!philabs!pwa-b!mmintl!franka Multimate International 52 Oakland Ave North E. Hartford, CT 06108