Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 beta 3/9/83; site frog.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!cybvax0!frog!john From: john@frog.UUCP (John Woods, Software) Newsgroups: net.lang.c Subject: Re: Two Birds with One Stone Message-ID: <303@frog.UUCP> Date: Tue, 24-Dec-85 11:23:41 EST Article-I.D.: frog.303 Posted: Tue Dec 24 11:23:41 1985 Date-Received: Thu, 26-Dec-85 04:13:14 EST References: <874@dataioDataio.UUCP> <864@kuling.UUCP> Organization: Charles River Data Systems, Framingham MA Lines: 32 > In article <874@dataioDataio.UUCP> bright@dataio.UUCP (Walter Bright writes: > >Almost but not quite true. A compiler CANNOT normally replace a divide > >by a right-shift if it is an integer divide. This is because a right > >shift of a negative integer is not the same as a divide. > > > However most useable processors provide arithmetic shifts which will give > the right result even if it is a signed divide. > -- > Thomas Hameenaho, Dept. of Computer Science, Uppsala University, Sweden Wrongo: Consider the following program: main() { int three = -3; printf("%d %d\n", three / 2, three >> 1); } What does it print? -1 -2 Division (usually) rounds negative numbers to zero, ASH-ing right to -infinity. -- John Woods, Charles River Data Systems, Framingham MA, (617) 626-1101 ...!decvax!frog!john, ...!mit-eddie!jfw, jfw%mit-ccc@MIT-XX.ARPA The Pentagon's Polygraphs: Witchcraft for witchhunts.