summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorerdgeist <de@gsmk.de>2014-10-06 23:01:40 +0200
committererdgeist <de@gsmk.de>2014-10-06 23:01:40 +0200
commit4a11447fbab4e00cfd207829a1e4d47c97f728db (patch)
treef7bb79906bb48629516db00c8261b983b2a962e1
parent7214d06d2d54dcfa770dd98e902a0397f208aec3 (diff)
Replace rest of hex constants with Q26 macros, also replace algorithm for arguments of fixexp with negative parameter with a more aggressive one
-rw-r--r--fixpow.c90
1 files changed, 45 insertions, 45 deletions
diff --git a/fixpow.c b/fixpow.c
index cb687b4..3dc4815 100644
--- a/fixpow.c
+++ b/fixpow.c
@@ -150,52 +150,52 @@ static uint32_t fixexp(int32_t x) {
150 t=x-TO_Q26(0.000122062862526); if(t>=0) x=t,y+=y>>13; /* log(1+1/8192) */ 150 t=x-TO_Q26(0.000122062862526); if(t>=0) x=t,y+=y>>13; /* log(1+1/8192) */
151 /* from here the values in Q26 become approx 2^n, so lets check bits 151 /* from here the values in Q26 become approx 2^n, so lets check bits
152 and fix the residual error below */ 152 and fix the residual error below */
153 if(x&0x0001000) y+=y>>14; 153 if(x&0x0001000) y+=y>>14;
154 if(x&0x0000800) y+=y>>15; 154 if(x&0x0000800) y+=y>>15;
155 if(x&0x0000400) y+=y>>16; 155 if(x&0x0000400) y+=y>>16;
156 if(x&0x0000200) y+=y>>17; 156 if(x&0x0000200) y+=y>>17;
157 if(x&0x0000100) y+=y>>18; 157 if(x&0x0000100) y+=y>>18;
158 if(x&0x0000080) y+=y>>19; 158 if(x&0x0000080) y+=y>>19;
159 if(x&0x0000040) y+=y>>20; 159 if(x&0x0000040) y+=y>>20;
160 if(x&0x0000020) y+=y>>21; 160 if(x&0x0000020) y+=y>>21;
161 if(x&0x0000010) y+=y>>22; 161 if(x&0x0000010) y+=y>>22;
162 if(x&0x0000008) y+=y>>23; 162 if(x&0x0000008) y+=y>>23;
163 if(x&0x0000004) y+=y>>24; 163 if(x&0x0000004) y+=y>>24;
164 if(x&0x0000002) y+=y>>25; 164 if(x&0x0000002) y+=y>>25;
165 if(x&0x0000001) y+=y>>26; 165 if(x&0x0000001) y+=y>>26;
166 } else { 166 } else {
167 x=-x; 167 x=-x;
168 t=x-0x162E42FE; if(t>=0) x=t,y>>=8; 168 t=x-TO_Q26(5.545177444479562); if(t>=0) x=t,y>>=8;
169 t=x-0x0B17217F; if(t>=0) x=t,y>>=4; 169 t=x-TO_Q26(2.772588722239781); if(t>=0) x=t,y>>=4;
170 t=x-0x058B90BF; if(t>=0) x=t,y>>=2; 170 t=x-TO_Q26(1.386294361119891); if(t>=0) x=t,y>>=2;
171 t=x-0x02C5C85F; if(t>=0) x=t,y>>=1; 171 t=x-TO_Q26(0.693147180559945); if(t>=0) x=t,y>>=1;
172 t=x-0x017FAFA3; if(t>=0) x=t,y-=(y>>2) + (y>>4); 172 t=x-TO_Q26(0.374693449441411); if(t>=0) x=t,y-=(y>>4) + (y>>2);
173 t=x-0x00D49F69; if(t>=0) x=t,y-=(y>>2) - (y>>4); 173 t=x-TO_Q26(0.207639364778244); if(t>=0) x=t,y-=(y>>2) - (y>>4);
174 t=x-0x00769C9D; if(t>=0) x=t,y-=(y>>3) - (y>>6); 174 t=x-TO_Q26(0.124642445207276); if(t>=0) x=t,y-=(y>>3) - (y>>7);
175 t=x-0x003DD463; if(t>=0) x=t,y-=(y>>4) - (y>>8); 175 t=x-TO_Q26(0.062457354933746); if(t>=0) x=t,y-=(y>>4) - (y>>9);
176 t=x-0x002082BB; if(t>=0) x=t,y-=y>>5; 176 t=x-TO_Q26(0.031244793038107); if(t>=0) x=t,y-=(y>>5) - (x>>11);
177 t=x-0x0010615C; if(t>=0) x=t,y-=(y>>6) + (y>>12); 177 t=x-TO_Q26(0.015748356968139); if(t>=0) x=t,y-=(y>>6);
178 t=x-0x0008488D; if(t>=0) x=t,y-=(y>>7) + (y>>12); 178 t=x-TO_Q26(0.007966216526084); if(t>=0) x=t,y-=(y>>7) + (y>>13);
179 t=x-0x00044243; if(t>=0) x=t,y-=(y>>8) + (y>>12); 179 t=x-TO_Q26(0.004036455850488); if(t>=0) x=t,y-=(y>>8) + (y>>13);
180 t=x-0x00038188; if(t>=0) x=t,y-=(y>>8) - (y>>11); 180 t=x-TO_Q26(0.002077351513834); if(t>=0) x=t,y-=(y>>9) + (y>>13);
181 t=x-0x0001E070; if(t>=0) x=t,y-=(y>>9) - (y>>13); 181 t=x-TO_Q26(0.001099236751907); if(t>=0) x=t,y-=(y>>10)+ (y>>13);
182 t=x-0x0000FC1F; if(t>=0) x=t,y-=(y>>10)- (y>>16); 182 t=x-TO_Q26(0.000610537902840); if(t>=0) x=t,y-=(y>>11)+ (y>>13);
183 t=x-0x00007F07; if(t>=0) x=t,y-=(y>>11)- (y>>18); 183 t=x-TO_Q26(0.000366278009100); if(t>=0) x=t,y-=(y>>12)+ (y>>13);
184 t=x-0x00003FC1; if(t>=0) x=t,y-=(y>>12)- (y>>20); 184 t=x-TO_Q26(0.000213645867528); if(t>=0) x=t,y-=(y>>12)- (y>>15);
185 if(x&0x0002000) y-=y>>13; 185 if(x&0x0002000) y-=y>>13;
186 if(x&0x0001000) y-=y>>14; 186 if(x&0x0001000) y-=y>>14;
187 if(x&0x0000800) y-=y>>15; 187 if(x&0x0000800) y-=y>>15;
188 if(x&0x0000400) y-=y>>16; 188 if(x&0x0000400) y-=y>>16;
189 if(x&0x0000200) y-=y>>17; 189 if(x&0x0000200) y-=y>>17;
190 if(x&0x0000100) y-=y>>18; 190 if(x&0x0000100) y-=y>>18;
191 if(x&0x0000080) y-=y>>19; 191 if(x&0x0000080) y-=y>>19;
192 if(x&0x0000040) y-=y>>20; 192 if(x&0x0000040) y-=y>>20;
193 if(x&0x0000020) y-=y>>21; 193 if(x&0x0000020) y-=y>>21;
194 if(x&0x0000010) y-=y>>22; 194 if(x&0x0000010) y-=y>>22;
195 if(x&0x0000008) y-=y>>23; 195 if(x&0x0000008) y-=y>>23;
196 if(x&0x0000004) y-=y>>24; 196 if(x&0x0000004) y-=y>>24;
197 if(x&0x0000002) y-=y>>25; 197 if(x&0x0000002) y-=y>>25;
198 if(x&0x0000001) y-=y>>26; 198 if(x&0x0000001) y-=y>>26;
199 } 199 }
200 200
201 return y; 201 return y;
@@ -229,7 +229,7 @@ int fixpow(int32_t *pow, int32_t base, int32_t exponent )
229#endif 229#endif
230 230
231 /* In Q16, fixexp overflows for values > 10,39720770839918 */ 231 /* In Q16, fixexp overflows for values > 10,39720770839918 */
232 if( log_base_times_exponent > TO_Q26(10,39720770839918) ) 232 if( log_base_times_exponent > TO_Q26(10.39720770839918) )
233 return -2; 233 return -2;
234 234
235 res = (int32_t)log_base_times_exponent; 235 res = (int32_t)log_base_times_exponent;