# to the nth power

Richard A. O'Keefe ok at goanna.cs.rmit.oz.au
Fri Nov 2 19:24:50 AEST 1990


In article <15984 at mentor.cc.purdue.edu>, edgincd2 at mentor.cc.purdue.edu (Chris Edgington *Computer Science Major*) writes:
> I don't know if this is what you are looking for, but this is a neat little
> trick to take a number to a power.

>      Answer = exp(ln(Root)*Exponent);

*Please* don't do that.  If you want to raise a number x to an integral
power n, use pow(x, (double)n).  That can handle negative numbers x
(x < 0), while exp(ln(x)*n) can't.  If you want to raise a number x to
a non-integral power y, use pow(x, y).  Why?  Because it can be a _lot_
more accurate.  (If you want to know why, read Cody&Waite.)

-- 
The problem about real life is that moving one's knight to QB3
may always be replied to with a lob across the net.  --Alasdair Macintyre.



More information about the Comp.lang.c mailing list