Path: utzoo!attcan!uunet!husc6!mailrus!uflorida!novavax!proxftl!twwells!bill From: bill@twwells.uucp (T. William Wells) Newsgroups: comp.lang.c Subject: Re: Efficient coding considered harmful? Message-ID: <149@twwells.uucp> Date: 6 Nov 88 04:57:13 GMT References: <3105@hubcap.UUCP> <34112@XAIT.XEROX.COM> <1700@dataio.Data-IO.COM> <136@twwells.uucp> <2730@hound.UUCP> Reply-To: bill@twwells.UUCP (T. William Wells) Followup-To: alt.flame Organization: None, Ft. Lauderdale Lines: 56 Summary: Expires: Sender: Distribution: Keywords: Grrrrrrr........ In article <2730@hound.UUCP> rkl1@hound.UUCP (K.LAUX) writes: : | : >... dividing positive numbers by powers of two should be done with a shift. : : I'm suprized that noone has questioned the validity of shifting : instead of dividing by (powers of) 2. No one has questioned it because, given the rider that *everyone* has attached (the thing being divided being positive), it *is* valid. : What about the difference between Logical and Arithmetic shifts? There is none, for positive numbers. : If you want to divide, then divide! A lot of compilers are smart enough : to implement the divide as a shift, but only where appropriate. And many are not. Worse, most frequently, the compiler can't determine whether the number really is positive. In fact, only the most advanced compilers are capable of this. The exception to this is when the number being divided is declared unsigned. So, the options are a cast which may or may not cause the optimizer to do what one wants, or a shift which will. : I *did* notice the condition of dividend being positive, But you obviously decided to ignore the condition. Or you failed to consider that it is a critical condition. : but now : you have to *guarantee* that it will always be positive. So? If I can't determine correctly that such is true, I have much worse problems than code which doesn't meet your approval. : As for the 'compiler being broken' if it doesn't do the same thing : for a shift and dividing, this is not true. In one case, you only told : it to shift, the other to do a divide: they made be *equivalent*, but : they certainly are not *equal*. Go back to school. If they aren't equal, then they aren't equivalent. If they are equivalent then the must be equal. Under appropriate restrictions, a>>b and a/(2**b) are equal, thus equivalent. : So, please, if you *functionally* require a divide by (powers of) 2, : code it as a divide and let the compiler *implement* it (maybe optimization : needs to be turned on). So please, get your head straight, and learn to think, before intruding your ignorance in the debates of your betters. --- Bill {uunet|novavax}!proxftl!twwells!bill