next up previous contents index Search
Next: 0.5.5 Julian Calendar Algorithms Up: 0.5 Miscellaneous Algorithms Previous: 0.5.3.2 References

0.5.4 Exponentiation

 
/* efficiantly compute x^n */

double pow(double x; int n) {
  double y = 1;
  int neg = (n < 0);

  if (neg) n = -n;

  while (n) {
    if (n & 1) y *= x;
    x *= x;
    n >>= 1;
  }
  return neg ? 1.0/y : y;
}

Scott Gasch
1999-07-09