1 /* 2 * Copyright (c) 1980 Regents of the University of California. 3 * All rights reserved. The Berkeley software License Agreement 4 * specifies the terms and conditions for redistribution. 5 * 6 * @(#)pow_hh.c 5.2 06/26/85 7 */ 8 9 short pow_hh(ap, bp) 10 short *ap, *bp; 11 { 12 short int pow, x, n; 13 14 pow = 1; 15 x = *ap; 16 n = *bp; 17 18 if (n == 0) 19 return ( 1L ); 20 21 if (x == 0) 22 { 23 if( n > 0 ) 24 return ( 0L ); 25 else 26 return ( 1/x ); 27 } 28 29 if (x == 1) 30 return ( 1L ); 31 32 if (x == -1) 33 { 34 if (n < 0) 35 { 36 if (n < -2) 37 n += 2; 38 n = -n; 39 } 40 if (n % 2 == 0) 41 return ( 1L ); 42 else 43 return ( -1L ); 44 } 45 46 if (n > 0) 47 for( ; ; ) 48 { 49 if(n & 01) 50 pow *= x; 51 if(n >>= 1) 52 x *= x; 53 else 54 break; 55 } 56 else 57 pow = 0; 58 59 return(pow); 60 } 61