00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include <math.h>
00042 #include "cmplrs/host.h"
00043 #include "cmplx.h"
00044 #include "defalias.h"
00045 #include "moremath.h"
00046
00047 #if defined(BUILD_OS_DARWIN)
00048 static void
00049 sincos(double d, double *s, double *c) {
00050 *s = sin(d);
00051 *c = cos(d);
00052 }
00053 #else
00054 extern void sincos(double, double *, double *);
00055 #endif
00056
00057 #ifdef KEY
00058 dcomplex __powzz(double adreal, double adimag, double bdreal, double bdimag)
00059 #else
00060 dcomplex __powzz(double adreal, double adimag, double_t bdreal, double_t bdimag)
00061 #endif // KEY
00062 {
00063 double logr, logi, x, y;
00064 double sinx, cosx;
00065 dcomplex r;
00066
00067 logr = log(hypot(adreal,adimag));
00068 logi = atan2(adimag,adreal);
00069
00070 x = exp(logr*bdreal-logi*bdimag);
00071 y = logr*bdimag+logi*bdreal;
00072
00073 sincos(y, &sinx, &cosx);
00074 r.dreal = x*cosx;
00075 r.dimag = x*sinx;
00076
00077 return r;
00078
00079
00080 }
00081
00082 void pow_zz_(dcomplex *r, dcomplex *a, dcomplex *b)
00083 {
00084 *r = __powzz(a->dreal, a->dimag, b->dreal, b->dimag);
00085 }
00086
00087 #if defined(BUILD_OS_DARWIN)
00088
00089 void pow_zz(dcomplex *r, dcomplex *a, dcomplex *b) { pow_zz_(r, a, b); }
00090 void pow_zz__(dcomplex *r, dcomplex *a, dcomplex *b) { pow_zz_(r, a, b); }
00091 #else
00092 defalias(pow_zz_, pow_zz);
00093 defalias(pow_zz_, pow_zz__);
00094 #endif