Path: utzoo!utgpu!water!watmath!clyde!cbosgd!ihnp4!ihlpf!nevin1 From: nevin1@ihlpf.ATT.COM (00704A-Liber) Newsgroups: comp.lang.c Subject: Re: Power operator? Message-ID: <3312@ihlpf.ATT.COM> Date: 9 Jan 88 00:57:05 GMT References: <47000029@uxe.cso.uiuc.edu> <10063@mimsy.UUCP> <646@l.cc.purdue.edu> Reply-To: nevin1@ihlpf.UUCP (00704A-Liber,N.) Organization: AT&T Bell Laboratories - Naperville, Illinois Lines: 44 In article <646@l.cc.purdue.edu> cik@l.cc.purdue.edu (Herman Rubin) writes: .In article <10063@mimsy.UUCP>, chris@mimsy.UUCP (Chris Torek) writes: .. In article <47000029@uxe.cso.uiuc.edu> mcdonald@uxe.cso.uiuc.edu writes: ...I've been wondering why there is no power operator in C. .. .. There is: .. a = pow(x, 7.); .I think everyone should consider this unsatisfactory. . .One reason is that requiring the writing of a subroutine call is that .this requires people to use that notation instead of writing . . x = y ** z or x = y ! z. . .Similar thinking would require one to write x = sub(y, z) instead of .x = y - z. This is a major design flaw in all HLLs which I know. In other words, are you saying that all functions of two variables which do not modify the variables should always be declared with infix notation?? I have a hard enough time remembering all the infix operators now (there are at least 19) and their order of precedence and associativity. :-) How would you define the order of precedence and associativity for these functions? . .Another is that there are _several_ power functions; the one in the standard .math library is the slowest one, which must be used if the exponent is non- .integral. Standard FORTRAN treats y ** z to be of the type of y if z is .typed integer, and most implementations use the binary representation of z to .compute the result in that case, and even to have several of the most important .cases "precoded", i.e, y ** 2 is usually done as y * y; even if this is not .done, in Torek's example, if it is known that the 7 is an integer the resulting .code will run at least an order of magnitude faster than the pow function. Write a function (call it mypow()) to call the correct pow() function depending on its arguments; why should this be built in to the language if you can easily define it with the operators given? That was fine for Fortran, a language designed to handle large amounts of number crunching. C is more general-purpose than that. (BTW, I really don't understand your 'use the binary implementation of z ...' remark.) -- _ __ NEVIN J. LIBER ..!ihnp4!ihlpf!nevin1 (312) 510-6194 ' ) ) "The secret compartment of my ring I fill / / _ , __o ____ with an Underdog super-energy pill." / (_