checked in for jerry
[unix-history] / usr / src / usr.bin / f77 / libF77 / pow_hh.c
CommitLineData
4e52e045 1/*
a7868ad7
RE
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 *
e6a2dc69 6 * @(#)pow_hh.c 5.2 %G%
4e52e045
DW
7 */
8
9short pow_hh(ap, bp)
10short *ap, *bp;
11{
e6a2dc69 12 short int pow, x, n;
4e52e045 13
e6a2dc69
JB
14 pow = 1;
15 x = *ap;
16 n = *bp;
4e52e045 17
e6a2dc69
JB
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)
4e52e045 35 {
e6a2dc69
JB
36 if (n < -2)
37 n += 2;
38 n = -n;
39 }
40 if (n % 2 == 0)
41 return ( 1L );
4e52e045 42 else
e6a2dc69
JB
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;
4e52e045 55 }
e6a2dc69
JB
56 else
57 pow = 0;
58
59 return(pow);
4e52e045 60}