Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!bellcore!decvax!decwrl!glacier!diablo!avg From: avg@diablo.ARPA (Allen VanGelder) Newsgroups: net.lang Subject: Re: Integer division: a winner declared Message-ID: <127@diablo.ARPA> Date: Sat, 15-Feb-86 21:47:13 EST Article-I.D.: diablo.127 Posted: Sat Feb 15 21:47:13 1986 Date-Received: Mon, 17-Feb-86 05:23:48 EST References: <11610@ucbvax.BERKELEY.EDU> <5100003@ccvaxa> <548@ism780c.UUCP> <1970@peora.UUCP> Reply-To: avg@diablo.UUCP (Allen VanGelder) Organization: Stanford University Lines: 18 Keywords: semi-:-) re the winner, Knuth, Ada, C Ada clearly has it right. Knuth agrees, but spells "rem" differently. Ada examples: 5/ 3 = 1 5 rem 3 = 2 5 mod 3 = 2 (-5)/ 3 = -1 -5 rem 3 = -2 -5 mod 3 = 1 5/(-3) = -1 5 rem -3 = 2 5 mod -3 = -2 (-5)/(-3) = 1 -5 rem -3 = -2 -5 mod -3 = -1 (a mod b) is the answer to the question, "What element in the field Z_b is congruent to a?" For b > 0, Z_b = {0,1,2,...,b-1} by standard definition. For b < 0 I am unaware of any standard definition, but we might as well define Z_b = {0,-1,-2,...,b+1}. Note that b+1 is the multiplicative identity. I can't imagine implementing -5/3 = -2. If you really need this, I would assume you also need the Ada "mod" on the same numbers. So do m = a mod b; q = (a - m) / b; with very little overhead.