home *** CD-ROM | disk | FTP | other *** search
/ Die Ultimative Software-P…i Collection 1996 & 1997 / Die Ultimative Software-Pakete CD-ROM fur Atari Collection 1996 & 1997.iso / g / gnu_c / pmlsrc23.zoo / pmlsrc / pow.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-19  |  582 b   |  49 lines

  1. /*
  2.     computes x^y.
  3.     uses log and exp
  4. */
  5.  
  6. #include    <errno.h>
  7. #include    <math.h>
  8. int errno;
  9.  
  10. #if __STDC__
  11. double log(double), exp(double);
  12. #else
  13. double log(), exp();
  14. #endif
  15.  
  16. double 
  17. pow(x,y)
  18. double x, y;
  19. {
  20.     double temp;
  21.     long l;
  22.  
  23.     if (y == 0.) {
  24.         if (x == 0.) goto domain;
  25.         return 1.0;
  26.     }
  27.     else if (x == 0.) {
  28.         if (y > 0.) return 0.;
  29.         else goto domain;
  30.     }
  31.  
  32.     if(x < 0.)
  33.     {
  34.         l = y;            /* is y an integer? */
  35.         if(l != y)
  36.             goto domain;
  37.         temp = exp(y * log(-x));
  38.         if(l & 1)
  39.             temp = -temp;
  40.         return(temp);
  41.     }
  42.  
  43.     return(exp(y * log(x)));
  44.  
  45. domain:
  46.     errno = EDOM;
  47.     return(HUGE_VAL);
  48. }
  49.