11#ifndef MATHLIB_MATHLIB_IQ_MATHLIB_IQ_H_
12#define MATHLIB_MATHLIB_IQ_MATHLIB_IQ_H_
65#define _IQ(x) ( ((x) < 0.0) ? (mc_t)((1<<BASE_IQ) * (x) - 0.5) :\
66 (mc_t)((1<<BASE_IQ) * (x) + 0.5) )
68#define _IQX_TO_IQY(x,qx,qy) (((qx)>(qy)) ? \
69 ((x) >> ((qx)-(qy))) \
70 : ((signed long int)(x) << ((qy)-(qx))))
72#define _IQX(x,qx) ((x) * ((mc_t)1 << (qx)))
74#define _FLOAT_TO_IQ(x, base) (((x) * (1 << (BASE_IQ)))/(base))
75#define _FLOAT_TO_IQY(x, base_iq ,base) (((float)(x) * ((mc_t)1 << (base_iq)))/(float)(base))
77#define _IQ_TO_FLOATY(x, base) ((float64_t)(((float64_t)(x)*(float64_t)(base)) / (float64_t)(1 << BASE_IQ)))
78#define _IQ_TO_FLOAT(x) ((float64_t)(((float64_t)(x)) / (float64_t)(1 << BASE_IQ)))
79#define _IQ_TO_FLOATZ(x, base_iq, base) ((float32_t)(((float32_t)(x)*(float32_t)(base)) / (float32_t)(1 << base_iq)))
81#define _IQ_TO_FLOATY(x, y, base) ((float32_t)(((float32_t)(x)*(float32_t)(base)) / (float32_t)(1 << y)))
82#define _IQ_TO_FLOAT(x) ((float32_t)(((float32_t)(x)) / (float32_t)(1 << BASE_IQ)))
84#define MATHLIB_MIN_VALUE ((mc_t)1)
90#define MATHLIB_IQMPY(a, b, a_format, b_format, out_format) ( (((a_format)+(b_format))>30) ? \
91 ( (mc_t)(((int64_t)(a) * (int64_t)(b)) >> ((a_format)+(b_format)-(out_format))) ) \
92 : ( (mc_t)(((mc_t)(a) * (mc_t)(b)) >> ((a_format)+(b_format)-(out_format))) ) )
93#define MATHLIB_MPY(a, b) MATHLIB_IQMPY(a, b, BASE_IQ, BASE_IQ, BASE_IQ)
95#define MATHLIB_DIV(x, y) ((((x) << BASE_IQ) / (y)))
97#define MATHLIB_ABS(x) ((x < 0) ? -x : x)
98#define MATHLIB_SAT(x, lim_inf, lim_sup) \
99 ((lim_sup) >= (lim_inf)) ? \
100 (((x) >= (lim_sup)) ? (lim_sup) : ( ((x) <= (lim_inf)) ? (lim_inf) : (x) )) : \
101 (((x) >= (lim_inf)) ? (lim_inf) : ( ((x) <= (lim_sup)) ? (lim_sup) : (x) ))
107#define MATHLIB_MPY_BY_TWO(a) ((a)<<1)
108#define MATHLIB_MPY_BY_FOUR(a) ((a)<<2)
109#define MATHLIB_MPY_BY_EIGHT(a) ((a)<<3)
110#define MATHLIB_DIV_BY_TWO(a) ((a)>>1)
111#define MATHLIB_DIV_BY_FOUR(a) ((a)>>2)
112#define MATHLIB_DIV_BY_EIGHT(a) ((a)>>3)
117#define MATHLIB_SQRT(x) MathLib_SqrtLUT((x))
118#define MATHLIB_SINCOS(th, sc) MathLib_SinCosIQ(th, sc)
119#define MATHLIB_MOD(x, y) MathLib_ModIq(x, y)
120#define MATHLIB_SINCOSMODAB(ab, m, sc) MathLib_SinCosModAbIq(ab, m, sc)
126#define ONE_OVER_PI _IQ(0.31830988618379067153776752674503)
127#define ONE_OVER_4PI _IQ(0.07957747154594766788444188168626/2)
128#define ONE_OVER_TWO _IQ(0.5)
129#define ONE_OVER_THREE _IQ(0.33333)
130#define ONE_OVER_SQRT3 _IQ(0.57735026918962576450914878050196)
131#define SQRT3_OVER_TWO _IQ(0.86602540378443864676372317075294)
132#define SQRT3 _IQ(0.86602540378443864676372317075294*2)
mc_t MathLib_ModIq(mc_t x, mc_t y)
Modulus function, it calculates hypotenusa in Q1.15.
void MathLib_SinCosIQ(mc_t theta, trig_t *sinCos)
Sin and Cosine calculation of a Q1.15 angle.
void MathLib_SinCosPoly(mc_t theta, trig_t *sinCos)
Calculates the sine and cosine using a sixth order polynomial approximation, the approximation is jus...
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...
void MathLib_SinCosModAbIq(AlphaBeta_t *ab, mc_t mod, trig_t *sinCos)
Modulus function, it calculates hypotenusa in Q1.15.