Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!ptimtc!nntp-server.caltech.edu!suncub.bbso.caltech.edu!EYCHANER From: eychaner@suncub.bbso.caltech.edu (Another casualty of applied metaphysics) Newsgroups: comp.lang.c Subject: Re: Bug fix for Turbo C Message-ID: <1991Jun30.235416.13636@nntp-server.caltech.edu> Date: 30 Jun 91 23:54:16 GMT References: <1991Jun26.155139.86965@vaxc.cc.monash.edu.au>,<1991Jun29.123505.21528@thunder.mcrcim.mcgill.edu> <1991Jun29.190505.10335@nntp-server.caltech.edu>,<6568@goanna.cs.rmit.oz.au> Sender: news@nntp-server.caltech.edu Reply-To: eychaner@suncub.bbso.caltech.edu Organization: Big Bear Solar Observatory, Caltech Lines: 32 ok@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. -G. ****************************************************************************** Glenn Eychaner - Big Bear Solar Observatory - eychaner@suncub.bbso.caltech.edu "There is no monopoly of common sense / On either side of the political fence" -Sting, "Russians"