On Fri, 12 Jun 1998, Glynn Clements wrote:
>...
> Which can be computed using:
> 
>       double pow(double a, int b)
>       {
>               double pow = 1.0;
>               int i;
>       
>               for (i = 0; i < 8*sizeof(int); i++)
>               {
>                       if (b & (1U << i))      /* if the ith bit of b is set */
>                               pow *= a;
>                       a *= a;                 /* a = a^2 */
>               }
>       
>               return pow;
>       }
> 
> However, all of this is general programming theory, rather than being
> specific to C.

What's wrong with using:

double pow(double a, int b) {
  return exp(b*log(a));
}

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

Pete

Pete Ryland     Home phone: +61 2 9697 9262     Mobile: 014 035 802
email: [EMAIL PROTECTED]  ICQ UIN: 4256333
WWW: http://www.pdr.ml.org      ftp: ftp.pdr.ml.org


Reply via email to