home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / f2csrc.zip / f2csrc / libF77 / pow_di.c < prev    next >
C/C++ Source or Header  |  1994-07-28  |  394b  |  35 lines

  1. #include "f2c.h"
  2.  
  3. #ifdef KR_headers
  4. double pow_di(ap, bp) doublereal *ap; integer *bp;
  5. #else
  6. double pow_di(doublereal *ap, integer *bp)
  7. #endif
  8. {
  9. double pow, x;
  10. integer n;
  11.  
  12. pow = 1;
  13. x = *ap;
  14. n = *bp;
  15.  
  16. if(n != 0)
  17.     {
  18.     if(n < 0)
  19.         {
  20.         n = -n;
  21.         x = 1/x;
  22.         }
  23.     for( ; ; )
  24.         {
  25.         if(n & 01)
  26.             pow *= x;
  27.         if(n >>= 1)
  28.             x *= x;
  29.         else
  30.             break;
  31.         }
  32.     }
  33. return(pow);
  34. }
  35.