Path: utzoo!utgpu!watserv1!watmath!att!ima!ima.isc.com From: karl@ima.isc.com (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: # to the nth power Message-ID: <5240@ima.ima.isc.com> Date: 5 Nov 90 06:08:53 GMT References: <90305.005050CJH101@psuvm.psu.edu> Sender: karl@ima.ima.isc.com Reply-To: karl@ima.isc.com (Karl Heuer) Organization: Interactive Systems Lines: 23 Supersedes: <1990Nov02.060401.17669@dirtydog.ima.isc.com> In article <90305.005050CJH101@psuvm.psu.edu> CJH101@psuvm.psu.edu (Carl J. Hixon) writes: >Why am I unable to find an opperator which raises a number to a power. (The >fortran equivalent of x**n) If you look up "exponentiation" in the index to K&R, you'll be directed to a page that mentions the non-existence of such an operator, and an example function that implements the integer-to-integer version. (And, if the K&R was 2nd edition, a mention of the existence of the real-to-real version in the standard library.) As to *why*, the usual explanation is that C operators tend to mirror common hardware instructions, with anything more complex (such as string copy) being implemented as a library function instead. This explanation isn't entirely satisfactory, and in fact I believe C should have had such an operator; but I'll continue that thread in alt.lang.cfutures. In article <1990Nov1.232830.17131@NCoast.ORG> catfood@NCoast.ORG (Mark W. Schumann) writes: > int result = 1; > for (i = exponent; i > 1; i--) result *= root; Fencepost error. Should be "i > 0". Karl W. Z. Heuer (karl@ima.isc.com or uunet!ima!karl), The Walking Lint