Something IBM did right (RT division of negatives).

Dave Jones djones at megatest.UUCP
Sat Nov 5 10:34:57 AEST 1988


>From article <11529 at bellcore.bellcore.com>, by sjs at 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.



More information about the Comp.lang.c mailing list