From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: ** X-Spam-Status: No, score=2.6 required=5.0 tests=BAYES_20,INVALID_DATE, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.3 4.3bsd-beta 6/6/85; site ucbvax.BERKELEY.EDU Path: utzoo!linus!decvax!bellcore!ulysses!ucbvax!brahms!gsmith From: gsmith@brahms.BERKELEY.EDU (Gene Ward Smith) Newsgroups: net.lang,net.lang.ada Subject: Re: Integer division: a winner declared Message-ID: <11957@ucbvax.BERKELEY.EDU> Date: Fri, 21-Feb-86 03:34:35 EST Article-I.D.: ucbvax.11957 Posted: Fri Feb 21 03:34:35 1986 Date-Received: Mon, 24-Feb-86 07:21:42 EST References: <11610@ucbvax.BERKELEY.EDU> <5100003@ccvaxa> <548@ism780c.UUCP> <1970@peora.UUCP> <127@diablo.ARPA> Sender: usenet@ucbvax.BERKELEY.EDU Reply-To: gsmith@brahms.UUCP (Gene Ward Smith) Organization: University of California, Berkeley Keywords: semi-:-) re the winner, Knuth, Ada, C Xref: linus net.lang:1918 net.lang.ada:645 List-Id: 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 > It looks like I need to unsay most of the bad things I said about Ada. Sorry about that, Adaphiles, but at first I thought J. Eric Roskos was saying Ada had two mod-type functions, but later decided he was saying it had only one (since he said Knuth's was different). I hope foot-in-mouth disease isn't catching. >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. There is a standard remainder defintion for negative b, but it really doesn't matter; the Knuth/Ada definition is just fine. >I can't imagine implementing -5/3 = -2. If you really need this, I Just today I needed this. It took an extra (C language) function definition. I have *never in my life*, to the best of my recollection, wanted or needed -5/2 = -1. It's not as important as mod by any means, so I will just leave you with this thought: it's still wrong, but the situation is improving. Maybe the next "language to end all languages" after Ada will finally get it right. ucbvax!brahms!gsmith Gene Ward Smith/UCB Math Dept/Berkeley CA 94720 ucbvax!weyl!gsmith "Dumb problem. DUMB!!!"