Path: utzoo!mnetor!uunet!husc6!bloom-beacon!gatech!udel!rochester!PT.CS.CMU.EDU!IUS1.CS.CMU.EDU!edw From: edw@IUS1.CS.CMU.EDU (Eddie Wyatt) Newsgroups: comp.lang.c Subject: Re: Power (Re: all those :-) Message-ID: <698@PT.CS.CMU.EDU> Date: 22 Jan 88 15:18:21 GMT References: <302@Aragorn.dde.uucp> <7139@brl-smoke.ARPA> <3461@ihlpf.ATT.COM> Sender: netnews@PT.CS.CMU.EDU Organization: Carnegie-Mellon University, CS/RI Lines: 36 > > > >If you do much geometric programming at all, you quickly realize > >that the squaring operator (expr ** 2) is quite heavily used. > > (pointer to pointer to 2 is heavily used?? :-)) Yes, but if you know that you > are going to be squaring you can replace it with (expr * expr) (possibly > needing temp variables depending on the side effects concerning expr), or write > a macro to do it for you. NO!!!! objection number 1. You missed part of the point in the dicussions about adding power which is having a infixed notation for the operator (we program in C here not Lisp :-)). BTW there exist a nice notation for pointers to pointers, **. Objection number 2, about the use of macros : you may find that macros don't cut it and here's why. Consider the macro definition for square : #define sqr(x) ((x)*(x)) used in the context of the macro : #define distance_2(x1,y1,x2,y2) \ sqrt((double) sqr((x1)-(x2)) + sqr((y1)-(y2))) The expressions ((x1) - (x2)) and ((y1) - (y2)) are evaluated twice. That means instead of the 2 multiplications, 2 subtractions, 1 addition and 1 subroutine call that the computation seems to need, it does 2 multi, 4 SUBS, 1 add, and 1 subroutine - two more floating point operations! This gets even worst if x1, y1, x2 or y2 are expressions themselves. Note the point being made for the second time is that macros can have so very subtle side effects. -- Eddie Wyatt e-mail: edw@ius1.cs.cmu.edu