Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site dataioDataio.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxt!houxm!vax135!cornell!uw-beaver!uw-june!entropy!dataio!bright From: bright@dataioDataio.UUCP (Walter Bright) Newsgroups: net.lang.c Subject: Re: Two Birds with One Stone Message-ID: <881@dataioDataio.UUCP> Date: Thu, 2-Jan-86 13:32:03 EST Article-I.D.: dataioDa.881 Posted: Thu Jan 2 13:32:03 1986 Date-Received: Fri, 3-Jan-86 08:12:03 EST References: <874@dataioDataio.UUCP> <864@kuling.UUCP> Reply-To: bright@dataio.UUCP (Walter Bright Organization: Data I/O Corp., Redmond WA Lines: 18 In article <864@kuling.UUCP> thomas@kuling.UUCP (Thomas H{meenaho) writes: >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. Ok, try this program: main() { printf("-3/2 = %d\n-3 >> 1 = %d\n",(-3)/2,(-3) >> 1); } I think you'll find the results are different, even when the compiler does an arithmetic right shift! (The difference is the direction in which rounding occurs.)