brazos-trapezoidal
MathLib_Float.h
Go to the documentation of this file.
1
11#ifndef MATHLIB_MATHLIB_FLOAT_MATHLIB_FLOAT_H_
12#define MATHLIB_MATHLIB_FLOAT_MATHLIB_FLOAT_H_
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17/*-------------------------------------------------------------*/
18/* Includes and dependencies */
19/*-------------------------------------------------------------*/
20#include "mc_types.h"
21
22/*-------------------------------------------------------------*/
23/* Typedefs enums & structs */
24/*-------------------------------------------------------------*/
25
26typedef struct
27{
28 mc_t a;
29 mc_t b;
30 mc_t c;
31}ABC_t;
32
33typedef struct
34{
35 mc_t d;
36 mc_t q;
37}DQ_t;
38
39typedef struct
40{
41 mc_t alpha;
42 mc_t beta;
44
45typedef struct
46{
47mc_t sin;
48mc_t cos;
49}trig_t;
50/*-------------------------------------------------------------*/
51/* Macros and definitions */
52/*-------------------------------------------------------------*/
54#define BASE_IQ (15)
55#define _IQ(x) (x)
56
57#define _IQX_TO_IQY(x,qx,qy) (x)
58
59#define _FLOAT_TO_IQ(x, base) (x)
60#define _FLOAT_TO_IQY(x, base_iq ,base) (x)
61#ifdef WINDOWS_BUILD
62#define _IQ_TO_FLOATY(x, y, base) ((float64_t)(x))
63#define _IQ_TO_FLOAT(x) ((float64_t)(x))
64#else
65#define _IQ_TO_FLOATY(x, y, base) ((float32_t)(x))
66#define _IQ_TO_FLOAT(x) ((float32_t)(x))
67#endif
68#define MATHLIB_MIN_VALUE ((mc_t)1e-12f)
71#define MATHLIB_IQMPY(a, b, a_format, b_format, out_format) ((a) * (b))
72#define MATHLIB_MPY(a, b) ((a) * (b))
73
74#define MATHLIB_DIV(x, y) ((x) / (y))
75
76#define MATHLIB_ABS(x) ((x < 0) ? -x : x)
77#define MATHLIB_SAT(x, lim_inf, lim_sup) \
78 ((lim_sup) >= (lim_inf)) ? \
79 (((x) >= (lim_sup)) ? (lim_sup) : ( ((x) <= (lim_inf)) ? (lim_inf) : (x) )) : \
80 (((x) >= (lim_inf)) ? (lim_inf) : ( ((x) <= (lim_sup)) ? (lim_sup) : (x) ))
82#define MATHLIB_MPY_BY_TWO(a) ((a) * 2)
83#define MATHLIB_MPY_BY_FOUR(a) ((a) * 4)
84#define MATHLIB_MPY_BY_EIGHT(a) ((a) * 8)
85#define MATHLIB_DIV_BY_TWO(a) ((a) * 0.5f)
86#define MATHLIB_DIV_BY_FOUR(a) ((a) * 0.25f)
87#define MATHLIB_DIV_BY_EIGHT(a) ((a) * 0.125f)
88
89
90#define MATHLIB_SQRT(x) MathLib_SqrtFromInvSqrt((x))
91#define MATHLIB_SINCOS(th, sc) MathLib_SinCos(th, sc)
92#define MATHLIB_MOD(x, y) MathLib_Mod(x, y)
93#define MATHLIB_SINCOSMODAB(ab, m, sc) MathLib_SinCosModAb(ab, m, sc)
94
95
97#define ONE_OVER_TWO (0.5f)
98#define ONE_OVER_THREE (0.33333f)
99#define ONE_OVER_SQRT3 (0.57735026918962576450914878050196f)
100#define SQRT3_OVER_TWO (0.86602540378443864676372317075294f)
101#define SQRT3 ((0.86602540378443864676372317075294f)*2)
102
103#define SIN_TABLE_SIZE 256
104#define COS_TABLE_OFFSET 64
105
106/*-------------------------------------------------------------*/
107/* Functions prototypes */
108/*-------------------------------------------------------------*/
109float32_t MathLib_Sqrt(float32_t value);
110float32_t MathLib_SqrtFlt(float32_t value);
111float32_t MathLib_SqrtFromInvSqrt(float32_t x);
112void MathLib_SinCos(mc_t theta, trig_t *sinCos);
113mc_t MathLib_Atan2(mc_t y, mc_t x);
114mc_t MathLib_Mod(mc_t x, mc_t y);
115void MathLib_SinCosModAb(AlphaBeta_t * ab, mc_t mod, trig_t *sinCos);
116/*-------------------------------------------------------------*/
117/* Inline Functions */
118/*-------------------------------------------------------------*/
119#ifdef __cplusplus
120 }
121#endif // C
122#endif /* MATHLIB_MATHLIB_FLOAT_MATHLIB_FLOAT_H_ */
void MathLib_SinCosModAb(AlphaBeta_t *ab, mc_t mod, trig_t *sinCos)
Modulus function, it calculates hypotenusa.
float32_t MathLib_Sqrt(float32_t value)
Calculates the square root of a floating point number.
mc_t MathLib_Atan2(mc_t y, mc_t x)
Atan2 function, it calculates the atan based on the x and y values.
float32_t MathLib_SqrtFlt(float32_t value)
Calculates the square root of a floating point number.
float32_t MathLib_SqrtFromInvSqrt(float32_t x)
Calculates the square root of a floating point number using the invSqrt method Referemce: https://bet...
void MathLib_SinCos(mc_t theta, trig_t *sinCos)
Sin and Cosine calculation of a floating point angle.
mc_t MathLib_Mod(mc_t x, mc_t y)
Modulus function, it calculates hypotenusa.
Contains generic typedefs that are able to change in case of different processors.