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 | * | |
d3a941af | 6 | * @(#)pow_ri.c 5.4 %G% |
683456d4 DW |
7 | */ |
8 | ||
d3a941af KB |
9 | #ifdef tahoe |
10 | #define double float | |
11 | #endif /* tahoe */ | |
683456d4 | 12 | |
d3a941af KB |
13 | float |
14 | pow_ri(ap, bp) | |
15 | float *ap; | |
16 | long *bp; | |
17 | { | |
18 | register long n = *bp; | |
19 | #ifdef tahoe | |
20 | register | |
21 | #endif /* tahoe */ | |
22 | double y, x = *ap; | |
683456d4 | 23 | |
d3a941af KB |
24 | if (!n) |
25 | return((double)1); | |
26 | if (n < 0) { | |
27 | x = (double)1 / x; | |
683456d4 | 28 | n = -n; |
d3a941af KB |
29 | } |
30 | while (!(n&1)) { | |
31 | x *= x; | |
32 | n >>= 1; | |
33 | } | |
34 | for (y = x; --n > 0; y *= x) | |
35 | while (!(n&1)) { | |
683456d4 | 36 | x *= x; |
d3a941af | 37 | n >>= 1; |
683456d4 | 38 | } |
d3a941af | 39 | return(y); |
683456d4 | 40 | } |
d3a941af KB |
41 | #ifdef tahoe |
42 | #undef double | |
43 | #endif /* tahoe */ |