brazos-trapezoidal
Classes | Macros | Functions
MathLib_Float.h File Reference
#include "mc_types.h"
Include dependency graph for MathLib_Float.h:

Go to the source code of this file.

Classes

struct  ABC_t
 
struct  DQ_t
 
struct  AlphaBeta_t
 
struct  trig_t
 

Macros

#define BASE_IQ   (15)
 
#define _IQ(x)   (x)
 
#define _IQX_TO_IQY(x, qx, qy)   (x)
 
#define _FLOAT_TO_IQ(x, base)   (x)
 
#define _FLOAT_TO_IQY(x, base_iq, base)   (x)
 
#define _IQ_TO_FLOATY(x, y, base)   ((float32_t)(x))
 
#define _IQ_TO_FLOAT(x)   ((float32_t)(x))
 
#define MATHLIB_MIN_VALUE   ((mc_t)1e-12f)
 
#define MATHLIB_IQMPY(a, b, a_format, b_format, out_format)   ((a) * (b))
 
#define MATHLIB_MPY(a, b)   ((a) * (b))
 
#define MATHLIB_DIV(x, y)   ((x) / (y))
 
#define MATHLIB_ABS(x)   ((x < 0) ? -x : x)
 
#define MATHLIB_SAT(x, lim_inf, lim_sup)
 
#define MATHLIB_MPY_BY_TWO(a)   ((a) * 2)
 
#define MATHLIB_MPY_BY_FOUR(a)   ((a) * 4)
 
#define MATHLIB_MPY_BY_EIGHT(a)   ((a) * 8)
 
#define MATHLIB_DIV_BY_TWO(a)   ((a) * 0.5f)
 
#define MATHLIB_DIV_BY_FOUR(a)   ((a) * 0.25f)
 
#define MATHLIB_DIV_BY_EIGHT(a)   ((a) * 0.125f)
 
#define MATHLIB_SQRT(x)   MathLib_SqrtFromInvSqrt((x))
 
#define MATHLIB_SINCOS(th, sc)   MathLib_SinCos(th, sc)
 
#define MATHLIB_MOD(x, y)   MathLib_Mod(x, y)
 
#define MATHLIB_SINCOSMODAB(ab, m, sc)   MathLib_SinCosModAb(ab, m, sc)
 
#define ONE_OVER_TWO   (0.5f)
 
#define ONE_OVER_THREE   (0.33333f)
 
#define ONE_OVER_SQRT3   (0.57735026918962576450914878050196f)
 
#define SQRT3_OVER_TWO   (0.86602540378443864676372317075294f)
 
#define SQRT3   ((0.86602540378443864676372317075294f)*2)
 
#define SIN_TABLE_SIZE   256
 
#define COS_TABLE_OFFSET   64
 

Functions

float32_t MathLib_Sqrt (float32_t value)
 Calculates the square root of a floating point number. More...
 
float32_t MathLib_SqrtFlt (float32_t value)
 Calculates the square root of a floating point number. More...
 
float32_t MathLib_SqrtFromInvSqrt (float32_t x)
 Calculates the square root of a floating point number using the invSqrt method Referemce: https://betterexplained.com/articles/understanding-quakes-fast-inverse-square-root/. More...
 
void MathLib_SinCos (mc_t theta, trig_t *sinCos)
 Sin and Cosine calculation of a floating point angle. More...
 
mc_t MathLib_Atan2 (mc_t y, mc_t x)
 Atan2 function, it calculates the atan based on the x and y values. More...
 
mc_t MathLib_Mod (mc_t x, mc_t y)
 Modulus function, it calculates hypotenusa. More...
 
void MathLib_SinCosModAb (AlphaBeta_t *ab, mc_t mod, trig_t *sinCos)
 Modulus function, it calculates hypotenusa. More...
 

Detailed Description


Author
Horacio Beckert Polli
Copyright 2018.  Theta Power Systems.  All rights reserved - CONFIDENTIAL ---------------------

Definition in file MathLib_Float.h.

Macro Definition Documentation

◆ _FLOAT_TO_IQ

#define _FLOAT_TO_IQ (   x,
  base 
)    (x)

Definition at line 59 of file MathLib_Float.h.

◆ _FLOAT_TO_IQY

#define _FLOAT_TO_IQY (   x,
  base_iq,
  base 
)    (x)

Definition at line 60 of file MathLib_Float.h.

◆ _IQ

#define _IQ (   x)    (x)

Definition at line 55 of file MathLib_Float.h.

◆ _IQ_TO_FLOAT

#define _IQ_TO_FLOAT (   x)    ((float32_t)(x))

Definition at line 66 of file MathLib_Float.h.

◆ _IQ_TO_FLOATY

#define _IQ_TO_FLOATY (   x,
  y,
  base 
)    ((float32_t)(x))

Definition at line 65 of file MathLib_Float.h.

◆ _IQX_TO_IQY

#define _IQX_TO_IQY (   x,
  qx,
  qy 
)    (x)

Definition at line 57 of file MathLib_Float.h.

◆ BASE_IQ

#define BASE_IQ   (15)

Defines the base IQ, unless otherwise noted, all the variables use this base

Definition at line 54 of file MathLib_Float.h.

◆ COS_TABLE_OFFSET

#define COS_TABLE_OFFSET   64

Definition at line 104 of file MathLib_Float.h.

◆ MATHLIB_ABS

#define MATHLIB_ABS (   x)    ((x < 0) ? -x : x)

Definition at line 76 of file MathLib_Float.h.

◆ MATHLIB_DIV

#define MATHLIB_DIV (   x,
  y 
)    ((x) / (y))

Definition at line 74 of file MathLib_Float.h.

◆ MATHLIB_DIV_BY_EIGHT

#define MATHLIB_DIV_BY_EIGHT (   a)    ((a) * 0.125f)

Definition at line 87 of file MathLib_Float.h.

◆ MATHLIB_DIV_BY_FOUR

#define MATHLIB_DIV_BY_FOUR (   a)    ((a) * 0.25f)

Definition at line 86 of file MathLib_Float.h.

◆ MATHLIB_DIV_BY_TWO

#define MATHLIB_DIV_BY_TWO (   a)    ((a) * 0.5f)

Definition at line 85 of file MathLib_Float.h.

◆ MATHLIB_IQMPY

#define MATHLIB_IQMPY (   a,
  b,
  a_format,
  b_format,
  out_format 
)    ((a) * (b))

Multiply two variables defined by BASE_IQ, assuming the integer part is never bigger than 1.41pu (1.41^2 would overflow the multiplication in the Q15 format

Definition at line 71 of file MathLib_Float.h.

◆ MATHLIB_MIN_VALUE

#define MATHLIB_MIN_VALUE   ((mc_t)1e-12f)

Definition at line 68 of file MathLib_Float.h.

◆ MATHLIB_MOD

#define MATHLIB_MOD (   x,
  y 
)    MathLib_Mod(x, y)

Definition at line 92 of file MathLib_Float.h.

◆ MATHLIB_MPY

#define MATHLIB_MPY (   a,
  b 
)    ((a) * (b))

Definition at line 72 of file MathLib_Float.h.

◆ MATHLIB_MPY_BY_EIGHT

#define MATHLIB_MPY_BY_EIGHT (   a)    ((a) * 8)

Definition at line 84 of file MathLib_Float.h.

◆ MATHLIB_MPY_BY_FOUR

#define MATHLIB_MPY_BY_FOUR (   a)    ((a) * 4)

Definition at line 83 of file MathLib_Float.h.

◆ MATHLIB_MPY_BY_TWO

#define MATHLIB_MPY_BY_TWO (   a)    ((a) * 2)

Multiply a variable by two, this macro was created to optimize multiplications by multiples of two in fixed point logic

Definition at line 82 of file MathLib_Float.h.

◆ MATHLIB_SAT

#define MATHLIB_SAT (   x,
  lim_inf,
  lim_sup 
)
Value:
((lim_sup) >= (lim_inf)) ? \
(((x) >= (lim_sup)) ? (lim_sup) : ( ((x) <= (lim_inf)) ? (lim_inf) : (x) )) : \
(((x) >= (lim_inf)) ? (lim_inf) : ( ((x) <= (lim_sup)) ? (lim_sup) : (x) ))

Definition at line 77 of file MathLib_Float.h.

◆ MATHLIB_SINCOS

#define MATHLIB_SINCOS (   th,
  sc 
)    MathLib_SinCos(th, sc)

Definition at line 91 of file MathLib_Float.h.

◆ MATHLIB_SINCOSMODAB

#define MATHLIB_SINCOSMODAB (   ab,
  m,
  sc 
)    MathLib_SinCosModAb(ab, m, sc)

Definition at line 93 of file MathLib_Float.h.

◆ MATHLIB_SQRT

#define MATHLIB_SQRT (   x)    MathLib_SqrtFromInvSqrt((x))

Definition at line 90 of file MathLib_Float.h.

◆ ONE_OVER_SQRT3

#define ONE_OVER_SQRT3   (0.57735026918962576450914878050196f)

Definition at line 99 of file MathLib_Float.h.

◆ ONE_OVER_THREE

#define ONE_OVER_THREE   (0.33333f)

Definition at line 98 of file MathLib_Float.h.

◆ ONE_OVER_TWO

#define ONE_OVER_TWO   (0.5f)

Constants

Definition at line 97 of file MathLib_Float.h.

◆ SIN_TABLE_SIZE

#define SIN_TABLE_SIZE   256

Definition at line 103 of file MathLib_Float.h.

◆ SQRT3

#define SQRT3   ((0.86602540378443864676372317075294f)*2)

Definition at line 101 of file MathLib_Float.h.

◆ SQRT3_OVER_TWO

#define SQRT3_OVER_TWO   (0.86602540378443864676372317075294f)

Definition at line 100 of file MathLib_Float.h.

Function Documentation

◆ MathLib_Atan2()

mc_t MathLib_Atan2 ( mc_t  y,
mc_t  x 
)

Atan2 function, it calculates the atan based on the x and y values.

Parameters
yy-axis value to be calculated
xx-axis value to be calculated
Returns
the angle

Definition at line 650 of file MathLib_Float.c.

◆ MathLib_Mod()

mc_t MathLib_Mod ( mc_t  x,
mc_t  y 
)

Modulus function, it calculates hypotenusa.

Parameters
yy-axis value to be calculated
xx-axis value to be calculated
Returns
hypotenusa

Definition at line 663 of file MathLib_Float.c.

◆ MathLib_SinCos()

void MathLib_SinCos ( mc_t  theta,
trig_t *  sinCos 
)

Sin and Cosine calculation of a floating point angle.

Parameters
thetathe angle
sinCospointer to the struct that will hold the results

Definition at line 591 of file MathLib_Float.c.

◆ MathLib_SinCosModAb()

void MathLib_SinCosModAb ( AlphaBeta_t *  ab,
mc_t  mod,
trig_t *  sinCos 
)

Modulus function, it calculates hypotenusa.

Parameters
yy-axis value to be calculated
xx-axis value to be calculated
Returns
hypotenusa

Definition at line 676 of file MathLib_Float.c.

◆ MathLib_Sqrt()

float32_t MathLib_Sqrt ( float32_t  value)

Calculates the square root of a floating point number.

Parameters
Floatingpoint input
Returns
Square root output

Definition at line 489 of file MathLib_Float.c.

◆ MathLib_SqrtFlt()

float32_t MathLib_SqrtFlt ( float32_t  value)

Calculates the square root of a floating point number.

Parameters
Floatingpoint input
Returns
Square root output

Definition at line 523 of file MathLib_Float.c.

◆ MathLib_SqrtFromInvSqrt()

float32_t MathLib_SqrtFromInvSqrt ( float32_t  x)

Calculates the square root of a floating point number using the invSqrt method Referemce: https://betterexplained.com/articles/understanding-quakes-fast-inverse-square-root/.

Parameters
Floatingpoint input
Returns
Square root output

Definition at line 565 of file MathLib_Float.c.