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!bellcore!decvax!linus!philabs!pwa-b!mmintl!franka From: franka@mmintl.UUCP (Frank Adams) Newsgroups: net.lang Subject: Re: Integer division: a winner declared Message-ID: <1164@mmintl.UUCP> Date: Tue, 4-Mar-86 16:28:12 EST Article-I.D.: mmintl.1164 Posted: Tue Mar 4 16:28:12 1986 Date-Received: Sat, 8-Mar-86 21:01:52 EST References: <11610@ucbvax.BERKELEY.EDU> <5100003@ccvaxa> <548@ism780c.UUCP> <1970@peora.UUCP> <127@diablo.ARPA> Reply-To: franka@mmintl.UUCP (Frank Adams) Organization: Multimate International, E. Hartford, CT Lines: 37 Keywords: semi-:-) re the winner, Knuth, Ada, C Summary: Not by me it isn't In article <127@diablo.ARPA> avg@diablo.UUCP (Allen VanGelder) writes: >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?" > >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. A step in the right direction, but it still doesn't divide and round. ALGOL does it this way, but it hasn't been heard from since. (By the way, one advantage of -5/3 = -2 is that it makes it easier to do a divide and round if one is not available already. One can write: (a + b / 2) / b instead of if (a > 0) then (a + b / 2) / b else (a - b / 2) / b or similar results from mucking around with some variant of the signum function.) Frank Adams ihnp4!philabs!pwa-b!mmintl!franka Multimate International 52 Oakland Ave North E. Hartford, CT 06108