Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site ucla-cs.ARPA Path: utzoo!linus!decvax!decwrl!pyramid!hplabs!sdcrdcf!ucla-cs!jimc From: jimc@ucla-cs.UUCP Newsgroups: net.math,net.arch Subject: Re: Integer division Message-ID: <9091@ucla-cs.ARPA> Date: Tue, 18-Feb-86 13:30:36 EST Article-I.D.: ucla-cs.9091 Posted: Tue Feb 18 13:30:36 1986 Date-Received: Thu, 20-Feb-86 00:10:43 EST References: <557@aesat.UUCP> Reply-To: jimc@ucla-cs.UUCP (Jim Carter) Organization: UCLA Computer Science Department Lines: 27 Xref: linus net.math:2492 net.arch:2369 In article <557@aesat.UUCP> bmw@aesat.UUCP (Bruce Walker) writes: >| Is there someone out there who *wants* a/b to round towards 0 (for reasons >| ucbvax!brahms!weemba Matthew P Wiener/UCB Math Dept/Berkeley CA 94720 > >Yes, *I* want a/b to round toward 0, and for a good (although selfish) >reason. (I also want divide to produce *both* result *and* remainder >which answers a question posed by someone else on just that point.) > >...When a logical block address is handed to me, I do an >integer divide by the number of sectors per track ... "Round" is a misnomer. I think the problem is, if the logical block number is negative, should the answer be made more or less positive? In other words, in (-16)/7 do you want the answer to be -2 or -3? I don't think I have ever had a situation where it mattered -- but remaindering is closely related, and it *does* matter there. Do you want (-16)%7 to be -2 or +5? In your disc example I think you would rather be on sector +5, track -3 rather than sector -2 track -2. Similarly for circular caches, hash tables, etc.etc. One point, though: most divisions and remainderings are of known-to-be positive quantities, and we want to avoid adding useless overhead to check unsigned quantities for being negative. It would be best if the hardware would let the remainder have the sign of the divisor, whatever the dividend is. (Ask for the moon and they might give it to you.) James F. Carter (213) 206-1306 UCLA-SEASnet; 2567 Boelter Hall; 405 Hilgard Ave.; Los Angeles, CA 90024 UUCP:...!{ihnp4,ucbvax,{hao!cepu}}!ucla-cs!jimc ARPA:jimc@locus.UCLA.EDU