Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/5/84; site ism780c.UUCP Path: utzoo!watmath!clyde!cbosgd!ukma!psuvm.bitnet!psuvax1!burdvax!sdcrdcf!ism780c!tim From: tim@ism780c.UUCP (Tim Smith) Newsgroups: net.math,net.arch Subject: Re: Integer division Message-ID: <628@ism780c.UUCP> Date: Fri, 14-Feb-86 15:43:10 EST Article-I.D.: ism780c.628 Posted: Fri Feb 14 15:43:10 1986 Date-Received: Tue, 18-Feb-86 06:49:04 EST References: <557@aesat.UUCP> Reply-To: tim@ism780c.UUCP (Tim Smith) Organization: Interactive Systems Corp., Santa Monica, CA Lines: 29 Xref: watmath net.math:2856 net.arch:2550 In article <557@aesat.UUCP> bmw@aesat.UUCP (Bruce Walker) writes: > >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 I write the firmware for the disk controller boards I design, I >want that code to run as fast as possible (so do you, if your machine >uses my board!). When a logical block address is handed to me, I do an >integer divide by the number of sectors per track which produces both a >quotient and remainder. The quotient will represent the track I should >seek, and the remainder represents the sector I should read. No extra >work is done, and all the micros I would normally use for this kind of >purpose do what I expect. > If your logical block numbers are >= 0, and your disks have a positive number of sectors per track, then round toward zero and round toward negative infinity are the same. If you were given a relative block number to seek to, say N blocks from the start of the current track, then N might be negative. In this case you would also want to round to negative infinity. For example, if we have 16 sectors per track, and want the logical sector -13 from the start of the current track, we want -13/16 = -1, and -13%16 = 3, so we go back one track and read sector 3. With round toward zero, we would get -13/16 = 0, -13%16 = -13, thus we try to read sector -13 of the current track. -- Tim Smith sdcrdcf!ism780c!tim || ima!ism780!tim || ihnp4!cithep!tim