Path: utzoo!mnetor!uunet!husc6!bloom-beacon!gatech!purdue!i.cc.purdue.edu!j.cc.purdue.edu!k.cc.purdue.edu!l.cc.purdue.edu!cik From: cik@l.cc.purdue.edu (Herman Rubin) Newsgroups: comp.lang.c Subject: Re: Power operator? Message-ID: <646@l.cc.purdue.edu> Date: 7 Jan 88 12:21:04 GMT References: <47000029@uxe.cso.uiuc.edu> <10063@mimsy.UUCP> Organization: Purdue University Statistics Department Lines: 39 Summary: Unsatisfactory 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: > > #include > ... > double a, x; > ... > a = pow(x, 7.); > > Unless you write `#undef pow' after `#include ', you may > get in line code (fpushf (fp-4); fftod; fpushd $0d7.0; fexpd etc). 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. 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. -- Herman Rubin, Dept. of Statistics, Purdue Univ., West Lafayette IN47907 Phone: (317)494-6054 hrubin@l.cc.purdue.edu (ARPA or UUCP) or hrubin@purccvm.bitnet