Path: utzoo!utgpu!water!watmath!clyde!cbosgd!ihnp4!ihlpf!nevin1 From: nevin1@ihlpf.ATT.COM (00704a-Liber) Newsgroups: comp.lang.c Subject: Re: Power (Re: all those :-) Message-ID: <3521@ihlpf.ATT.COM> Date: 28 Jan 88 00:47:48 GMT References: <302@Aragorn.dde.uucp> <7139@brl-smoke.ARPA> <3461@ihlpf.ATT.COM> <698@PT.CS.CMU.EDU> Reply-To: nevin1@ihlpf.UUCP (00704a-Liber,N.J.) Organization: AT&T Bell Laboratories - Naperville, Illinois Lines: 46 In article <698@PT.CS.CMU.EDU> edw@IUS1.CS.CMU.EDU (Eddie Wyatt) writes: .I wrote (put some credits in :-)): .> 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 :-)). Then where is the operator for string concatenation, and square root, and everything other binary function that is used by C programmers? If you want a method added to C for inserting infix functions (something I do not want) then say so; but, the normal way to add functions to C is with prefix notation. . 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. Let me rephrase objection number 2: Here is a bad macro for defining squaring. Since the macro given doesn't work in all cases, a power operator should be added to C. [This is my opinion of objection #2] This is not good enough reasoning in my book! As I suggested before, you need temp variables to get this macro right! Don't add features to the language just because some programmers don't know how to get it right! -- _ __ NEVIN J. LIBER ..!ihnp4!ihlpf!nevin1 (312) 510-6194 ' ) ) "The secret compartment of my ring I fill / / _ , __o ____ with an Underdog super-energy pill." / (_