Commit | Line | Data |
---|---|---|
683456d4 | 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 | * | |
af857331 | 6 | * @(#)pow_ri.c 5.3 %G% |
683456d4 DW |
7 | */ |
8 | ||
9 | float pow_ri(ap, bp) | |
10 | float *ap; | |
11 | long int *bp; | |
12 | { | |
13 | double pow, x; | |
14 | long int n; | |
15 | ||
16 | pow = 1; | |
17 | x = *ap; | |
18 | n = *bp; | |
19 | ||
20 | if(n != 0) | |
21 | { | |
22 | if(n < 0) | |
23 | { | |
24 | if(x == 0) | |
25 | { | |
af857331 | 26 | return(pow); |
683456d4 DW |
27 | } |
28 | n = -n; | |
29 | x = 1/x; | |
30 | } | |
af857331 KM |
31 | if (x == 0) |
32 | return(0); | |
33 | ||
683456d4 DW |
34 | for( ; ; ) |
35 | { | |
36 | if(n & 01) | |
37 | pow *= x; | |
38 | if(n >>= 1) | |
39 | x *= x; | |
40 | else | |
41 | break; | |
42 | } | |
43 | } | |
af857331 | 44 | return(pow); |
683456d4 | 45 | } |