Path: utzoo!attcan!uunet!lll-winken!arisia!sgi!decwrl!megatest!djones From: djones@megatest.UUCP (Dave Jones) Newsgroups: comp.lang.c Subject: Re: Something IBM did right (RT division of negatives). Message-ID: <973@goofy.megatest.UUCP> Date: 5 Nov 88 00:34:57 GMT References: <11529@bellcore.bellcore.com> Organization: Megatest Corporation, San Jose, Ca Lines: 51 From article <11529@bellcore.bellcore.com>, by sjs@jcricket.ctt.bellcore.com (Stan Switzer): > Please, do not argue that integer -1/2 should be -1 so that the sign > is the same as -1.0/2.0 or because "by the laws of arithmetic" (-1)/2 > equals -(1/2). These are pointless arguments that have no useful > consequences as far as correct programs are concerned. > > Anyone wishing to take up the other side of the argument must find an > example of an actual situation where having -1/2 yield -1 is useful. > (The example must yield cases where the quotient can be both positive > or negative, otherwise I can just add or subtract one to the result > and get the same effect). > While I don't want to concede that the way you have restricted debate on this is justified, but I'll bite anyway. I'll use the second example you gave immediately after the challenge. > I offer the following examples in favor of the the "modular" > interpretation: > ... > > 2) Bit extraction: To get the n'th bit from the current (char) pointer > "p" (0 bit is low) use "bit = (p[i/BITSPERCHAR]>>(i%BITSPERCHAR)) & 1" > This comes up in rasterization code often enough. The usual solution > is to jimmy it so that you avoid negative "i" (or just use >>3 and &7 > instead). > In the scheme of things you propose, bit[-1] has the same location as bit[7]. Is that what you want? Change the meaning of (-1)/BITSPERCHR to be -1, and every bit gets its own happy home. Good enough? Best regards, Dave J.