Go to the documentation of this file.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 #include <math.h>
00037 #include "cmplrs/host.h"
00038 #include "moremath.h"
00039 #include "cmplx.h"
00040 #include "c_div.h"
00041
00042 complex __powci(float areal, float aimag, int32 n)
00043 {
00044 float_t t;
00045 complex x, p;
00046
00047 p.real = 1;
00048 p.imag = 0;
00049
00050 if(n == 0)
00051 return p;
00052
00053 if(n < 0) {
00054 n = -n;
00055 x = __cdiv(p.real, p.imag, areal, aimag);
00056 } else {
00057 x.real = areal;
00058 x.imag = aimag;
00059 }
00060
00061 for( ; ; ) {
00062 if(n & 01) {
00063 t = p.real * x.real - p.imag * x.imag;
00064 p.imag = p.real * x.imag + p.imag * x.real;
00065 p.real = t;
00066 }
00067 if(n >>= 1) {
00068 t = x.real * x.real - x.imag * x.imag;
00069 x.imag = 2 * x.real * x.imag;
00070 x.real = t;
00071 } else {
00072 break;
00073 }
00074 }
00075
00076 return p;
00077 }
00078
00079 void pow_ci(complex *p, complex *a, int32 *b)
00080 {
00081 *p = __powci(a->real, a->imag, *b);
00082 }
00083
00084 void
00085 pow_ci_(complex *p, complex *a, int32 *b)
00086 {
00087 *p = __powci(a->real, a->imag, *b);
00088 }
00089
00090 void
00091 pow_ci__(complex *p, complex *a, int32 *b)
00092 {
00093 *p = __powci(a->real, a->imag, *b);
00094 }
00095
00096 complex __powcl(float areal, float aimag, int64 n)
00097 {
00098 float_t t;
00099 complex x, p;
00100
00101 p.real = 1;
00102 p.imag = 0;
00103
00104 if(n == 0)
00105 return p;
00106
00107 if(n < 0) {
00108 n = -n;
00109 x = __cdiv(p.real, p.imag, areal, aimag);
00110 } else {
00111 x.real = areal;
00112 x.imag = aimag;
00113 }
00114
00115 for( ; ; ) {
00116 if(n & 01) {
00117 t = p.real * x.real - p.imag * x.imag;
00118 p.imag = p.real * x.imag + p.imag * x.real;
00119 p.real = t;
00120 }
00121 if(n >>= 1) {
00122 t = x.real * x.real - x.imag * x.imag;
00123 x.imag = 2 * x.real * x.imag;
00124 x.real = t;
00125 } else {
00126 break;
00127 }
00128 }
00129
00130 return p;
00131 }
00132
00133 void pow_cl(complex *p, complex *a, int64 *b)
00134 {
00135 *p = __powcl(a->real, a->imag, *b);
00136 }
00137
00138 void
00139 pow_cl_(complex *p, complex *a, int64 *b)
00140 {
00141 *p = __powcl(a->real, a->imag, *b);
00142 }
00143
00144 void
00145 pow_cl__(complex *p, complex *a, int64 *b)
00146 {
00147 *p = __powcl(a->real, a->imag, *b);
00148 }