1 /**************************************************************** 2 Copyright 1990 - 1997 by AT&T, Lucent Technologies and Bellcore. 3 4 Permission to use, copy, modify, and distribute this software 5 and its documentation for any purpose and without fee is hereby 6 granted, provided that the above copyright notice appear in all 7 copies and that both that the copyright notice and this 8 permission notice and warranty disclaimer appear in supporting 9 documentation, and that the names of AT&T, Bell Laboratories, 10 Lucent or Bellcore or any of their entities not be used in 11 advertising or publicity pertaining to distribution of the 12 software without specific, written prior permission. 13 14 AT&T, Lucent and Bellcore disclaim all warranties with regard to 15 this software, including all implied warranties of 16 merchantability and fitness. In no event shall AT&T, Lucent or 17 Bellcore be liable for any special, indirect or consequential 18 damages or any damages whatsoever resulting from loss of use, 19 data or profits, whether in an action of contract, negligence or 20 other tortious action, arising out of or in connection with the 21 use or performance of this software. 22 ****************************************************************/ 23 24 #include "f2c.h" 25 26 #ifdef __cplusplus 27 extern "C" { 28 #endif 29 30 /* Integer */ pow_hh(shortint * ap,shortint * bp)31 shortint pow_hh(shortint *ap, shortint *bp) 32 { 33 return (shortint)(pow(*ap, *bp)); 34 } pow_ii(integer * ap,integer * bp)35 integer pow_ii(integer *ap, integer *bp) 36 { 37 return (integer)(pow(*ap, *bp)); 38 } 39 #ifdef INTEGER_STAR_8 pow_qq(longint * ap,longint * bp)40 longint pow_qq(longint *ap, longint *bp) 41 { 42 return (longint)(pow(*ap, *bp)); 43 } 44 #endif 45 46 /* Double */ pow_ri(real * ap,integer * bp)47 double pow_ri(real *ap, integer *bp) 48 { 49 return (pow(*ap, *bp)); 50 } pow_dd(doublereal * ap,doublereal * bp)51 double pow_dd(doublereal *ap, doublereal *bp) 52 { 53 return (pow(*ap, *bp)); 54 } pow_di(doublereal * ap,integer * bp)55 double pow_di(doublereal *ap, integer *bp) 56 { 57 return (pow(*ap, *bp)); 58 } 59 60 /* Complex */ pow_ci(complex * p,complex * a,integer * b)61 void pow_ci(complex *p, complex *a, integer *b) 62 { 63 doublecomplex p1, a1; 64 65 a1.r = a->r; 66 a1.i = a->i; 67 68 pow_zi(&p1, &a1, b); 69 70 p->r = p1.r; 71 p->i = p1.i; 72 } pow_zz(doublecomplex * r,doublecomplex * a,doublecomplex * b)73 void pow_zz(doublecomplex *r, doublecomplex *a, doublecomplex *b) 74 { 75 double logr, logi, x, y; 76 77 logr = log( hypot(a->r, a->i) ); 78 logi = atan2(a->i, a->r); 79 80 x = exp( logr * b->r - logi * b->i ); 81 y = logr * b->i + logi * b->r; 82 83 r->r = x * cos(y); 84 r->i = x * sin(y); 85 } pow_zi(doublecomplex * p,doublecomplex * a,integer * b)86 void pow_zi(doublecomplex *p, doublecomplex *a, integer *b) 87 { 88 integer n; 89 unsigned long u; 90 double t; 91 doublecomplex q, x; 92 static doublecomplex one = {1.0, 0.0}; 93 94 n = *b; 95 q.r = 1; 96 q.i = 0; 97 98 if(n == 0) 99 goto done; 100 if(n < 0) 101 { 102 n = -n; 103 z_div(&x, &one, a); 104 } 105 else 106 { 107 x.r = a->r; 108 x.i = a->i; 109 } 110 111 for(u = n; ; ) 112 { 113 if(u & 01) 114 { 115 t = q.r * x.r - q.i * x.i; 116 q.i = q.r * x.i + q.i * x.r; 117 q.r = t; 118 } 119 if(u >>= 1) 120 { 121 t = x.r * x.r - x.i * x.i; 122 x.i = 2 * x.r * x.i; 123 x.r = t; 124 } 125 else 126 break; 127 } 128 done: 129 p->i = q.i; 130 p->r = q.r; 131 } 132 133 134 #ifdef __cplusplus 135 } 136 #endif 137 138