# to the nth power
Karl Heuer
karl at ima.isc.com
Mon Nov 5 17:08:53 AEST 1990
In article <90305.005050CJH101 at psuvm.psu.edu> CJH101 at 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 at NCoast.ORG> catfood at 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 at ima.isc.com or uunet!ima!karl), The Walking Lint
More information about the Comp.lang.c
mailing list