brazos-trapezoidal
MathLib_Iq.c
Go to the documentation of this file.
1
12 /*-------------------------------------------------------------*/
13 /* Includes and dependencies */
14 /*-------------------------------------------------------------*/
15#include "MathLib.h"
16 /*-------------------------------------------------------------*/
17 /* Typedefs enums & structs */
18 /*-------------------------------------------------------------*/
19
20 /*-------------------------------------------------------------*/
21 /* Macros and definitions */
22 /*-------------------------------------------------------------*/
24#define SIZE_SQRT_TABLE_2N 7
25#define SIN_TABLE_SIZE 512
27//#define SIZE_SIN_TABLE_2N 8
28#define COS_TABLE_OFFSET 128
29//#define SINTABLE_DIV_COEF PI*(1<<16)
30
32#define SIN_POL_A0 _IQ(0.70710781187)
33#define SIN_POL_A2 _IQ(-0.872348075361)
34#define SIN_POL_A4 _IQ(0.179251759526)
35#define SIN_POL_A6 _IQ(-0.0142718282624)
36#define SIN_POL_B1 _IQ(-1.11067032264)
37#define SIN_POL_B3 _IQ(0.4561589075945)
38#define SIN_POL_B5 _IQ(-0.0539104694791)
40#define ATAN_POL_A7 _IQ(-1.57588)
41#define ATAN_POL_A5 _IQ(1.48697)
42#define ATAN_POL_A3 _IQ(-0.817719)
43#define ATAN_POL_A1 _IQ(0.63611725)
44#define ATAN_POL_A0 _IQ(0.25)
45
46 /*-------------------------------------------------------------*/
47 /* Global Variables */
48 /*-------------------------------------------------------------*/
49
50 /*-------------------------------------------------------------*/
51 /* Local Variables */
52 /*-------------------------------------------------------------*/
53//const uint16_t SquareRootLUT[] = { 0, 2907, 4112, 5036, 5815, 6501, 7122, 7693, 8224, 8723,
54// 9194, 9643, 10072, 10483, 10879, 11261, 11630, 11988, 12336, 12674, 13003, 13324,
55// 13638, 13944, 14244, 14538, 14826, 15108, 15386, 15658, 15926, 16189, 16448, 16703,
56// 16954, 17202, 17446, 17686, 17924, 18158, 18389, 18618, 18843, 19066, 19287, 19505,
57// 19720, 19934, 20145, 20353, 20560, 20765, 20967, 21168, 21367, 21564, 21759, 21952,
58// 22144, 22334, 22522, 22709, 22895, 23079, 23261, 23442, 23622, 23800, 23977, 24153,
59// 24327, 24500, 24672, 24843, 25012, 25181, 25348, 25514, 25680, 25844, 26007, 26169,
60// 26330, 26490, 26649, 26807, 26964, 27121, 27276, 27431, 27584, 27737, 27889, 28040,
61// 28191, 28340, 28489, 28637, 28784, 28931, 29076, 29221, 29366, 29509, 29652, 29794,
62// 29936, 30077, 30217, 30357, 30496, 30634, 30772, 30909, 31045, 31181, 31316, 31451,
63// 31585, 31719, 31852, 31984, 32116, 32247, 32378, 32508, 32638, 32767 };
64
65const uint16_t SquareRootLUT[] = { 0, 2896, 4096, 5016, 5792, 6476, 7094, 7663, 8192, 8689,
66 9159, 9606, 10033, 10442, 10837, 11217, 11585, 11941, 12288, 12624, 12952, 13272,
67 13584, 13890, 14189, 14481, 14768, 15049, 15325, 15597, 15863, 16125, 16384, 16638,
68 16888, 17134, 17377, 17617, 17854, 18087, 18317, 18545, 18770, 18992, 19211, 19428,
69 19643, 19855, 20066, 20274, 20479, 20683, 20885, 21085, 21283, 21479, 21673, 21866,
70 22057, 22246, 22434, 22620, 22805, 22988, 23170, 23350, 23529, 23707, 23883, 24058,
71 24232, 24404, 24575, 24745, 24914, 25082, 25249, 25414, 25579, 25742, 25905, 26066,
72 26226, 26386, 26544, 26702, 26858, 27014, 27169, 27323, 27476, 27628, 27780, 27930,
73 28080, 28229, 28377, 28524, 28671, 28817, 28962, 29107, 29250, 29393, 29536, 29677,
74 29818, 29959, 30098, 30237, 30376, 30514, 30651, 30787, 30923, 31059, 31193, 31327,
75 31461, 31594, 31727, 31858, 31990, 32121, 32251, 32381, 32510, 32639, 32767 };
76
77//const uint16_t SquareRootLUT[] = { 0,5815,8224,10072,11631,13003,14244,15386,16448,17446,
78// 18390,19287,20145,20967,21759,22523,23261,23977,24672,25348,26007,26649,
79// 27276,27889,28489,29076,29652,30217,30772,31316,31852,32378,32896,33406,
80// 33909,34404,34892,35373,35848,36316,36779,37236,37687,38133,38574,39010,
81// 39441,39868,40290,40707,41120,41529,41935,42336,42733,43127,43518,43904,
82// 44288,44668,45045,45419,45790,46157,46522,46884,47244,47600,47954,48305,
83// 48654,49001,49344,49686,50025,50362,50697,51029,51359,51687,52014,52338,
84// 52660,52980,53298,53614,53929,54241,54552,54861,55169,55474,55778,56081,
85// 56381,56680,56978,57274,57568,57861,58153,58443,58732,59019,59305,59589,
86// 59872,60154,60434,60713,60991,61268,61543,61817,62090,62362,62633,62902,
87// 63170,63437,63703,63968,64232,64495,64756,65017,65276,65535 };
88
89
90//static const int16_t sinTable[SIN_TABLE_SIZE] =
91//{
92//0,804,1608,2410,3212,4011,4808,5602,
93//6393,7179,7962,8739,9512,10278,11039,11793,
94//12539,13279,14010,14732,15446,16151,16846,17530,
95//18204,18868,19519,20159,20787,21403,22005,22594,
96//23170,23731,24279,24811,25329,25832,26319,26790,
97//27245,27683,28105,28510,28898,29268,29621,29956,
98//30273,30571,30852,31113,31356,31580,31785,31971,
99//32137,32285,32412,32521,32609,32678,32728,32757,
100//32767,32757,32728,32678,32609,32521,32412,32285,
101//32137,31971,31785,31580,31356,31113,30852,30571,
102//30273,29956,29621,29268,28898,28510,28105,27683,
103//27245,26790,26319,25832,25329,24811,24279,23731,
104//23170,22594,22005,21403,20787,20159,19519,18868,
105//18204,17530,16846,16151,15446,14732,14010,13279,
106//12539,11793,11039,10278,9512,8739,7962,7179,
107//6393,5602,4808,4011,3212,2410,1608,804,
108//0,-804,-1608,-2410,-3212,-4011,-4808,-5602,
109//-6393,-7179,-7962,-8739,-9512,-10278,-11039,-11793,
110//-12539,-13279,-14010,-14732,-15446,-16151,-16846,-17530,
111//-18204,-18868,-19519,-20159,-20787,-21403,-22005,-22594,
112//-23170,-23731,-24279,-24811,-25329,-25832,-26319,-26790,
113//-27245,-27683,-28105,-28510,-28898,-29268,-29621,-29956,
114//-30273,-30571,-30852,-31113,-31356,-31580,-31785,-31971,
115//-32137,-32285,-32412,-32521,-32609,-32678,-32728,-32757,
116//-32767,-32757,-32728,-32678,-32609,-32521,-32412,-32285,
117//-32137,-31971,-31785,-31580,-31356,-31113,-30852,-30571,
118//-30273,-29956,-29621,-29268,-28898,-28510,-28105,-27683,
119//-27245,-26790,-26319,-25832,-25329,-24811,-24279,-23731,
120//-23170,-22594,-22005,-21403,-20787,-20159,-19519,-18868,
121//-18204,-17530,-16846,-16151,-15446,-14732,-14010,-13279,
122//-12539,-11793,-11039,-10278,-9512,-8739,-7962,-7179,
123//-6393,-5602,-4808,-4011,-3212,-2410,-1608,-804
124//};
125
126//Sin table IQ15
127static const int16_t sinTable[SIN_TABLE_SIZE] =
128{
129 402,804,1206,1608,2009,2411,2811,3212,3612,4011,4410,4808,5205,5602,5998,6393,
130 6787,7180,7571,7962,8351,8740,9127,9512,9896,10279,10660,11039,11417,11793,12167,12540,
131 12910,13279,13646,14010,14373,14733,15091,15447,15800,16151,16500,16846,17190,17531,17869,18205,
132 18538,18868,19195,19520,19841,20160,20475,20788,21097,21403,21706,22006,22302,22595,22884,23170,
133 23453,23732,24008,24279,24548,24812,25073,25330,25583,25833,26078,26320,26557,26791,27020,27246,
134 27467,27684,27897,28106,28311,28511,28707,28899,29086,29269,29448,29622,29792,29957,30118,30274,
135 30425,30572,30715,30853,30986,31114,31238,31357,31471,31581,31686,31786,31881,31972,32058,32138,
136 32214,32286,32352,32413,32470,32522,32568,32610,32647,32679,32706,32729,32746,32758,32766,32767,
137 32766,32758,32746,32729,32706,32679,32647,32610,32568,32522,32470,32413,32352,32286,32214,32138,
138 32058,31972,31881,31786,31686,31581,31471,31357,31238,31114,30986,30853,30715,30572,30425,30274,
139 30118,29957,29792,29622,29448,29269,29086,28899,28707,28511,28311,28106,27897,27684,27467,27246,
140 27020,26791,26557,26320,26078,25833,25583,25330,25073,24812,24548,24279,24008,23732,23453,23170,
141 22884,22595,22302,22006,21706,21403,21097,20788,20475,20160,19841,19520,19195,18868,18538,18205,
142 17869,17531,17190,16846,16500,16151,15800,15447,15091,14733,14373,14010,13646,13279,12910,12540,
143 12167,11793,11417,11039,10660,10279,9896,9512,9127,8740,8351,7962,7571,7180,6787,6393,
144 5998,5602,5205,4808,4410,4011,3612,3212,2811,2411,2009,1608,1206,804,402,0,
145 -402,-804,-1206,-1608,-2009,-2411,-2811,-3212,-3612,-4011,-4410,-4808,-5205,-5602,-5998,-6393,
146 -6787,-7180,-7571,-7962,-8351,-8740,-9127,-9512,-9896,-10279,-10660,-11039,-11417,-11793,-12167,-12540,
147 -12910,-13279,-13646,-14010,-14373,-14733,-15091,-15447,-15800,-16151,-16500,-16846,-17190,-17531,-17869,-18205,
148 -18538,-18868,-19195,-19520,-19841,-20160,-20475,-20788,-21097,-21403,-21706,-22006,-22302,-22595,-22884,-23170,
149 -23453,-23732,-24008,-24279,-24548,-24812,-25073,-25330,-25583,-25833,-26078,-26320,-26557,-26791,-27020,-27246,
150 -27467,-27684,-27897,-28106,-28311,-28511,-28707,-28899,-29086,-29269,-29448,-29622,-29792,-29957,-30118,-30274,
151 -30425,-30572,-30715,-30853,-30986,-31114,-31238,-31357,-31471,-31581,-31686,-31786,-31881,-31972,-32058,-32138,
152 -32214,-32286,-32352,-32413,-32470,-32522,-32568,-32610,-32647,-32679,-32706,-32729,-32746,-32758,-32766,-32767,
153 -32766,-32758,-32746,-32729,-32706,-32679,-32647,-32610,-32568,-32522,-32470,-32413,-32352,-32286,-32214,-32138,
154 -32058,-31972,-31881,-31786,-31686,-31581,-31471,-31357,-31238,-31114,-30986,-30853,-30715,-30572,-30425,-30274,
155 -30118,-29957,-29792,-29622,-29448,-29269,-29086,-28899,-28707,-28511,-28311,-28106,-27897,-27684,-27467,-27246,
156 -27020,-26791,-26557,-26320,-26078,-25833,-25583,-25330,-25073,-24812,-24548,-24279,-24008,-23732,-23453,-23170,
157 -22884,-22595,-22302,-22006,-21706,-21403,-21097,-20788,-20475,-20160,-19841,-19520,-19195,-18868,-18538,-18205,
158 -17869,-17531,-17190,-16846,-16500,-16151,-15800,-15447,-15091,-14733,-14373,-14010,-13646,-13279,-12910,-12540,
159 -12167,-11793,-11417,-11039,-10660,-10279,-9896,-9512,-9127,-8740,-8351,-7962,-7571,-7180,-6787,-6393,
160 -5998,-5602,-5205,-4808,-4410,-4011,-3612,-3212,-2811,-2411,-2009,-1608,-1206,-804,-402,0
161};
162
163//Sin table IQ16
164//static const int32_t sinTable[SIN_TABLE_SIZE] =
165//{
166// 0,806,1611,2417,3222,4027,4830,5634,6436,7237,8038,8837,9635,10431,11226,12019,
167// 12810,13599,14386,15171,15954,16735,17512,18288,19060,19829,20596,21359,22120,22876,23630,24380,
168// 25126,25868,26606,27341,28071,28797,29519,30236,30948,31656,32360,33058,33751,34439,35122,35800,
169// 36472,37139,37800,38455,39105,39749,40386,41018,41643,42262,42875,43481,44081,44673,45260,45839,
170// 46411,46977,47535,48086,48630,49167,49696,50217,50731,51237,51736,52227,52709,53184,53651,54110,
171// 54560,55002,55436,55862,56279,56688,57088,57479,57862,58236,58601,58957,59305,59643,59973,60293,
172// 60604,60906,61199,61483,61757,62022,62277,62524,62760,62988,63205,63414,63612,63801,63980,64150,
173// 64310,64460,64601,64731,64852,64963,65065,65156,65238,65309,65371,65423,65465,65498,65520,65532,
174// 65535,65527,65510,65483,65446,65399,65342,65275,65198,65112,65015,64909,64793,64667,64532,64386,
175// 64231,64066,63892,63708,63514,63311,63098,62875,62643,62402,62151,61891,61621,61342,61054,60756,
176// 60450,60134,59809,59475,59132,58780,58420,58050,57672,57285,56889,56484,56072,55650,55220,54782,
177// 54336,53881,53419,52948,52469,51982,51488,50985,50475,49957,49432,48899,48359,47812,47257,46695,
178// 46126,45550,44967,44378,43782,43179,42569,41953,41331,40703,40068,39427,38781,38128,37470,36806,
179// 36137,35462,34781,34096,33405,32709,32009,31303,30593,29878,29158,28435,27706,26974,26238,25497,
180// 24753,24005,23254,22498,21740,20978,20213,19445,18674,17900,17124,16345,15563,14779,13993,13205,
181// 12415,11622,10829,10033,9236,8438,7638,6837,6035,5232,4429,3624,2819,2014,1209,403,
182// -403,-1209,-2014,-2819,-3624,-4429,-5232,-6035,-6837,-7638,-8438,-9236,-10033,-10829,-11622,-12415,
183// -13205,-13993,-14779,-15563,-16345,-17124,-17900,-18674,-19445,-20213,-20978,-21740,-22498,-23254,-24005,-24753,
184// -25497,-26238,-26974,-27706,-28435,-29158,-29878,-30593,-31303,-32009,-32709,-33405,-34096,-34781,-35462,-36137,
185// -36806,-37470,-38128,-38781,-39427,-40068,-40703,-41331,-41953,-42569,-43179,-43782,-44378,-44967,-45550,-46126,
186// -46695,-47257,-47812,-48359,-48899,-49432,-49957,-50475,-50985,-51488,-51982,-52469,-52948,-53419,-53881,-54336,
187// -54782,-55220,-55650,-56072,-56484,-56889,-57285,-57672,-58050,-58420,-58780,-59132,-59475,-59809,-60134,-60450,
188// -60756,-61054,-61342,-61621,-61891,-62151,-62402,-62643,-62875,-63098,-63311,-63514,-63708,-63892,-64066,-64231,
189// -64386,-64532,-64667,-64793,-64909,-65015,-65112,-65198,-65275,-65342,-65399,-65446,-65483,-65510,-65527,-65535,
190// -65532,-65520,-65498,-65465,-65423,-65371,-65309,-65238,-65156,-65065,-64963,-64852,-64731,-64601,-64460,-64310,
191// -64150,-63980,-63801,-63612,-63414,-63205,-62988,-62760,-62524,-62277,-62022,-61757,-61483,-61199,-60906,-60604,
192// -60293,-59973,-59643,-59305,-58957,-58601,-58236,-57862,-57479,-57088,-56688,-56279,-55862,-55436,-55002,-54560,
193// -54110,-53651,-53184,-52709,-52227,-51736,-51237,-50731,-50217,-49696,-49167,-48630,-48086,-47535,-46977,-46411,
194// -45839,-45260,-44673,-44081,-43481,-42875,-42262,-41643,-41018,-40386,-39749,-39105,-38455,-37800,-37139,-36472,
195// -35800,-35122,-34439,-33751,-33058,-32360,-31656,-30948,-30236,-29519,-28797,-28071,-27341,-26606,-25868,-25126,
196// -24380,-23630,-22876,-22120,-21359,-20596,-19829,-19060,-18288,-17512,-16735,-15954,-15171,-14386,-13599,-12810,
197// -12019,-11226,-10431,-9635,-8837,-8038,-7237,-6436,-5634,-4830,-4027,-3222,-2417,-1611,-806,0
198//};
199
200 /*-------------------------------------------------------------*/
201 /* Functions prototypes */
202 /*-------------------------------------------------------------*/
203
204 /*-------------------------------------------------------------*/
205 /* Functions */
206 /*-------------------------------------------------------------*/
207
216u_mc_t MathLib_SqrtLUT(uint16_t value)
217{
218 uint16_t ind;
219 mc_t rtn;
220 uint32_t tmp;
221
222
223 if(value >= _IQ(1.0f))
224 {
225 value = _IQ(1.0f)-1;
226 }
227 ind = value >> (SIZE_SQRT_TABLE_2N + 1);
228 ind = MATHLIB_SAT(ind, 0, (1 << SIZE_SQRT_TABLE_2N));
229//
230 if (ind < ((1 << SIZE_SQRT_TABLE_2N) - 2))
231 {
235 tmp = value % (1 << (BASE_IQ - SIZE_SQRT_TABLE_2N));
236 rtn = ((uint32_t)(((uint32_t)SquareRootLUT[ind + 1] - (uint32_t)SquareRootLUT[ind])*tmp) >> (BASE_IQ - SIZE_SQRT_TABLE_2N)) + (uint32_t)SquareRootLUT[ind];
237 }
238 else
239 {
240 rtn = SquareRootLUT[ind];
241 }
242 return(rtn);
243}
244
253void MathLib_SinCosPoly(mc_t theta, trig_t *sinCos)
254{
255 mc_t quadrant;
256 register mc_t xsqr;
257 register mc_t x;
258 register mc_t even;
259 register mc_t odd;
261 quadrant = (theta >> (BASE_IQ - 1));
263 x = theta & ((1 << (BASE_IQ - 1)) - 1);
265 x = (x << 1) - _IQ(0.5);
266 xsqr = MATHLIB_MPY(x, x);
267 even = MATHLIB_MPY(SIN_POL_A6, xsqr) + SIN_POL_A4;
268 even = MATHLIB_MPY(xsqr, even) + SIN_POL_A2;
269 even = MATHLIB_MPY(xsqr, even) + SIN_POL_A0;
270 odd = MATHLIB_MPY(SIN_POL_B5, xsqr) + SIN_POL_B3;
271 odd = MATHLIB_MPY(xsqr, odd) + SIN_POL_B1;
272 odd = MATHLIB_MPY(x, odd);
273 switch (quadrant)
274 {
275 case -2:
276 sinCos->sin = -even + odd;
277 sinCos->cos = -even - odd;
278 break;
279 case -1:
280 sinCos->sin = -even - odd;
281 sinCos->cos = even - odd;
282 break;
283 case 0:
284 sinCos->sin = even - odd;
285 sinCos->cos = even + odd;
286 break;
287 case 1:
288 sinCos->sin = even + odd;
289 sinCos->cos = -even + odd;
290 break;
291 }
292}
293
301void MathLib_SinCosIQ(mc_t theta, trig_t *sinCos)
302{
303 uint32_t tempU32;
304 uint32_t tableIndex;
305 int16_t remainder; /* use sign number for resolution */
306 int16_t y0;
307 int16_t y1;
308 mc_t sin;
309 mc_t cos;
310
311 if(theta >= _IQ(1.0f))
312 {
313 theta = _IQ(1.0f)-1;
314 }
315 else if (theta <= _IQ(-1.0f))
316 {
317 theta = _IQ(-1.0f);
318 }
319
320// tableIndex = theta >> (BASE_IQ - SIZE_SIN_TABLE_2N); // (2^15)/(2^8) = 2^7
321
322 tempU32 = (uint32_t)(((uint16_t)theta * (uint32_t)SIN_TABLE_SIZE));
323 tableIndex = tempU32>>16;
324
325 if(tableIndex >= SIN_TABLE_SIZE)
326 {
327 tableIndex = SIN_TABLE_SIZE - 1;
328 }
329 remainder = ( tempU32 & 0xFFFF) >> 1; /* convert to 1.15 */
330 if (remainder == 0)
331 {
332 sin = sinTable[ tableIndex ];
333 cos = sinTable[ ( tableIndex + COS_TABLE_OFFSET ) & ( SIN_TABLE_SIZE - 1 ) ];
334 }
335 else
336 {
337 y0 = sinTable[ tableIndex ];
338 y1 = sinTable[ ( tableIndex + 1 ) & ( SIN_TABLE_SIZE - 1 ) ];
339 y1 = ( ( y1 - y0 ) * remainder * (mc_t)2 ) / (mc_t)65536; /* y1 become delta */
340 sin = y0 + y1;
341
342 y0 = sinTable[ ( tableIndex + COS_TABLE_OFFSET ) & ( SIN_TABLE_SIZE - 1 ) ];
343 y1 = sinTable[ ( tableIndex + COS_TABLE_OFFSET + 1 ) & ( SIN_TABLE_SIZE - 1 ) ];
344 y1 = ( ( y1 - y0 ) * remainder * (mc_t)2 ) / (mc_t)65536; /* y1 become delta */
345 cos = y0 + y1;
346 }
347
348 /* assign output as float*/
349 sinCos->sin = sin;
350 sinCos->cos = cos;
351
352}
353
354
363mc_t MathLib_ModIq(mc_t x, mc_t y)
364{
365 return MathLib_SqrtLUT(MATHLIB_MPY(x,x) + MATHLIB_MPY(y,y));
366}
367
368
377void MathLib_SinCosModAbIq(AlphaBeta_t * ab, mc_t mod, trig_t *sinCos)
378{
379 trig_t out;
380 mc_t tmpcos;
381 mc_t tmpsin;
382
383// tmpcos = MATHLIB_DIV(ab->alpha, (mod+MATHLIB_MIN_VALUE));
384// if(tmpcos > _IQ(1.0f)) {
385// tmpcos = _IQ(1.0f);
386// }
387// if(tmpcos < _IQ(-1.0f)) {
388// tmpcos = _IQ(-1.0f);
389// }
390// tmpsin = MATHLIB_DIV(ab->beta, (mod+MATHLIB_MIN_VALUE));
391// if(tmpsin > _IQ(1.0f)) {
392// tmpsin = _IQ(1.0f);
393// }
394// if(tmpsin < _IQ(-1.0f)) {
395// tmpsin = _IQ(-1.0f);
396// }
397//
398// sinCos->sin = tmpsin;
399// sinCos->cos = tmpcos;
400
401 tmpcos = (ab->alpha / (mod+MATHLIB_MIN_VALUE));
402 if(tmpcos > _IQ(1.0f)) {
403 tmpcos = _IQ(1.0f);
404 }
405 if(tmpcos < _IQ(-1.0f)) {
406 tmpcos = _IQ(-1.0f);
407 }
408 tmpsin = (ab->beta / (mod+MATHLIB_MIN_VALUE));
409 if(tmpsin > _IQ(1.0f)) {
410 tmpsin = _IQ(1.0f);
411 }
412 if(tmpsin < _IQ(-1.0f)) {
413 tmpsin = _IQ(-1.0f);
414 }
415
416 sinCos->sin = tmpsin;
417 sinCos->cos = tmpcos;
418
419}
420
421
422
431{
432 register mc_t asqr;
433 register mc_t rtn;
434
435 asqr = MATHLIB_MPY(a, a);
436 rtn = MATHLIB_MPY(ATAN_POL_A7, asqr) + ATAN_POL_A5;
437 rtn = MATHLIB_MPY(asqr, rtn) + ATAN_POL_A3;
438 rtn = MATHLIB_MPY(asqr, rtn) + ATAN_POL_A1;
439 rtn = MATHLIB_MPY(a, rtn);
440 rtn += ATAN_POL_A0;
441 return rtn;
442}
443
444
453mc_t MathLib_Atan2Poly(mc_t y, mc_t x)
454{
455 register mc_t tmp;
456 if (x > 0)
457 {
458 if (y >= 0)
459 {
460 tmp = MATHLIB_DIV(y - x, y + x);
461 tmp = tmp >> 1;
462 return MathLib_AtanPoly(tmp);
463 }
464 else
465 {
466 tmp = MATHLIB_DIV(y + x, y - x);
467 tmp = tmp >> 1;
468 return -MathLib_AtanPoly(tmp);
469 }
470 }
471 else if (x < 0)
472 {
473 if (y >= 0)
474 {
475 tmp = MATHLIB_DIV(y + x, y - x);
476 tmp = tmp >> 1;
477 return (_IQ(1.0) - MathLib_AtanPoly(tmp));
478 }
479 else
480 {
481 tmp = MATHLIB_DIV(y - x, y + x);
482 tmp = tmp >> 1;
483 return (MathLib_AtanPoly(tmp) - _IQ(1.0));
484 }
485 }
486 else
487 {
488 if (y > 0)
489 {
490 return _IQ(1.0);
491 }
492 else if (y < 0)
493 {
494 return _IQ(-1.0);
495 }
496 else
497 {
498 return 0;
499 }
500 }
501}
502
mc_t MathLib_ModIq(mc_t x, mc_t y)
Modulus function, it calculates hypotenusa in Q1.15.
Definition: MathLib_Iq.c:363
mc_t MathLib_AtanPoly(mc_t a)
Calculates the atangent from a IQ number.
Definition: MathLib_Iq.c:430
#define SIZE_SQRT_TABLE_2N
Definition: MathLib_Iq.c:24
#define SIN_POL_A0
Definition: MathLib_Iq.c:32
#define COS_TABLE_OFFSET
Definition: MathLib_Iq.c:28
void MathLib_SinCosIQ(mc_t theta, trig_t *sinCos)
Sin and Cosine calculation of a Q1.15 angle.
Definition: MathLib_Iq.c:301
void MathLib_SinCosPoly(mc_t theta, trig_t *sinCos)
Calculates the sine and cosine using a sixth order polynomial approximation, the approximation is jus...
Definition: MathLib_Iq.c:253
u_mc_t MathLib_SqrtLUT(uint16_t value)
Calculates the square root of IQ1.15 number using a Look-up table that needs to have a size of a powe...
Definition: MathLib_Iq.c:216
#define ATAN_POL_A7
Definition: MathLib_Iq.c:40
void MathLib_SinCosModAbIq(AlphaBeta_t *ab, mc_t mod, trig_t *sinCos)
Modulus function, it calculates hypotenusa in Q1.15.
Definition: MathLib_Iq.c:377
mc_t MathLib_Atan2Poly(mc_t y, mc_t x)
Atan2 function, it calculates the atan based on the x and y values.
Definition: MathLib_Iq.c:453
#define BASE_IQ
Definition: MathLib_Iq.h:64