home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / f2c / f77lib / pow_hh.c < prev    next >
C/C++ Source or Header  |  2000-06-22  |  401b  |  32 lines

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