Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!decvax!genrad!panda!talcott!harvard!seismo!vrdxhq!rlgvax!hadron!jsdy From: jsdy@hadron.UUCP (Joseph S. D. Yao) Newsgroups: net.math,net.lang.c,net.arch Subject: Re: Integer division Message-ID: <246@hadron.UUCP> Date: Mon, 10-Feb-86 11:54:51 EST Article-I.D.: hadron.246 Posted: Mon Feb 10 11:54:51 1986 Date-Received: Thu, 13-Feb-86 17:36:26 EST References: <11603@ucbvax.BERKELEY.EDU> <4917@alice.UUCP> <367@mcgill-vision.UUCP> <685@brl-smoke.ARPA> Reply-To: jsdy@hadron.UUCP (Joseph S. D. Yao) Organization: Hadron, Inc., Fairfax, VA Lines: 61 Keywords: int, div, rem, mod Xref: linus net.math:2462 net.lang.c:7293 net.arch:2306 Summary: (1) return quot & rem (2) mod != rem (!!!!!) In article <685@brl-smoke.ARPA> gwyn@brl.ARPA writes: >What I would like is for the language to provide a notation >for obtaining BOTH the quotient and the remainder of an >integer division in a single operation. C doesn't provide a notation for an op with two returns, so this might be a little hard. (How I Did It:) On a PDP-11 with no FPP and V6 (that long ago), I wrote the long div/rem functions. Since the work involved was massive, I saved the operands, the quotient, and the remainder. If subsequent calls had the same operands, I just returned the already-computed values! If a div or rem is "cheap", this loses. However, if it is done in microcode the same way, this technique is recommended to the microcoders. >This % vs. Mod debate is rather silly. C's % operator is >NOT repeat NOT intended to be a modulo operator, although >people often use it that way for positive operands. Hooray. Modulo() != Remainder() except under certain circumstances, as this branch of net.flame has shown. I was at the point of posting this myself, the discussion was getting so disgusting (not to mention ad hominem -- or ad speciem). My degrees and first job titles all said "mathematics". Subsequent job titles have included phrases like "computer scientist" and "software engineer." This may qualify me to speak. (One degree also says "CS", and > 1 decade of experience lends credence to "engineer".) I consider each occupation to be superior to the others in what they do. Period. I don't expect the M or SE to immediately see a CS point of view, nor an SE or CS the M point of view, or any of the other possible permutations. SE's and programmers have made the remainder function what it is because the specs said so -- great! CS'ers, who don't use i m p l e m e n t e d languages unless they have to, are free to use mod() or rem() as they please. Mathematicians (pure) use anything they want, as long as it's in the realm of pure thought. Mathematicians (applied) have to use the tools that are available: so it is necessary for the SE's to provide their users d o c u m e n t a t i o n that clearly says, e.g., what rem is (it isn't mod, for instance). Then it is necessary for the users to r e a d said documentation, before complaining. Or take a class and l i s t e n . (No, I'm not saying none of my students ever did -- just the ones that complained most that they didn't understand. ;-}) All >reasonable mathematicians agree on what the definition of > a mod b >is for positive b and negative a. That should not be >confused with what the result of > a % b >should be under similar circumstances. C intentionally >hedges a bit on the meaning of % in such a case (which >makes that a generally inadvisable situation to allow to >arise in one's C code). -- Joe Yao hadron!jsdy@seismo.{CSS.GOV,ARPA,UUCP}