Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!hao!gatech!bbn!rochester!crowl From: crowl@cs.rochester.edu (Lawrence Crowl) Newsgroups: comp.arch Subject: Shift and Subtract is NOT Multiply Message-ID: <7276@sol.ARPA> Date: 1 Mar 88 16:57:35 GMT References: <7649@pur-ee.UUCP> Reply-To: crowl@cs.rochester.edu (Lawrence Crowl) Organization: U of Rochester, CS Dept, Rochester, NY Lines: 12 In article <7649@pur-ee.UUCP> hankd@pur-ee.UUCP (Hank Dietz) writes: >For example, a multiply by 7 (not a nice power of 2) is really shift to >multiply by 8 and then subtract the original number. If you use this method for multiplication by 7, and you do not provide for a double width result, using subtraction will lose the overflow information. For example, a*7 implemented as (a<<3)-a may overflow where (a<<2)+(a<<1)+a will not. If we detect an overflow with (a<<3)-a, then we cannot immediately tell whether or not a*7 would overflow. -- Lawrence Crowl 716-275-9499 University of Rochester crowl@cs.rochester.edu Computer Science Department ...!{allegra,decvax,rutgers}!rochester!crowl Rochester, New York, 14627