Bug fix for Turbo C

Another casualty of applied metaphysics eychaner at suncub.bbso.caltech.edu
Mon Jul 1 09:54:16 AEST 1991

ok at goanna.cs.rmit.oz.au (Richard A. O'Keefe) writes:
>I (Another casualty of applied metaphysics.) write:
>> short a_250K_array[];				/* The big array */
>> int bit_shift,					/* Bit shift */
>>     array_size, i;				/* Array size and index */
>> for (i = 0; i < arraysize; i++) {
>>     a_250K_array[i] >>= bit_shift;
>>     /* I shouldn't index the array like this; but it makes the code clearer */
>>     }
>> What I want is to divide each member of the 250K short array by 2^bit_shift.
>> The 250K array contains both positive and negative numbers.
>This has been beaten to death in SIGPLAN Notices over the years, but
>are you aware that "arithmetic right shift k bits" is _NOT_ the same
>thing as "divide by 2**k"?  For example,
>	((-1) /  2) == 0,
>but	((-1) >> 1) == -1

Yeah, I know, I know.  So it's not REALLY division by 2^k.  So sue me.  (BTW,
it is division by 2^k for all numbers EXCEPT -1, is it not?)

>If you're not worried about portability, you may not have a problem.

Well, I'm not worried about portability.

Glenn Eychaner - Big Bear Solar Observatory - eychaner at suncub.bbso.caltech.edu
"There is no monopoly of common sense / On either side of the political fence"
                                                            -Sting, "Russians"

More information about the Comp.lang.c mailing list