Pete Ryland wrote:

> What's wrong with using:
> 
> double pow(double a, int b) {
>   return exp(b*log(a));
> }

Nothing in particular. However, the algorithm that I posted:

a) Doesn't require the use of any library functions.

b) Takes advantage of the fact that the exponent is an integer. It may
be faster, particularly if you don't have a hardware FPU. Also, it may 
be more accurate, e.g. if `a' is equal to an integer, then pow(a,b)
should also be equal to an integer.

c) can also be applied to the case where both operands are integers.

> Don't a lot of processors have instructions for doing "exp" and "log"?

Yep. However, not all systems have a hardware FPU, and Linux runs on
some of those which don't (e.g. 386, 486SX).

-- 
Glynn Clements <[EMAIL PROTECTED]>

Reply via email to