/* Some usefull constants (6.10 format only)*/
#define FPZERO (0x0000)
#define FPONE (0x0400)
#define FPTEN (0x2800)
#define FPPI (0x0c91)
#define FP2PI (0x1922)
#define FPHALFPI (0x0648)
#define FPSQRT2 (0x05a8)
/* M.N fixed point format */
#define M (6)
#define N (10)
#define NMASK (0x3ff)
typedef int16_t fp_t;
typedef int32_t fpdbl_t;
/*
* *****************************************************************************
* Public function prototypes and macros
* *****************************************************************************
*/
#define max(a,b) (((a)>(b)) ? (a):(b))
#define min(a,b) (((a)<(b)) ? (a):(b))
//#define abs(a) (((a)<(0)) ? -(a):(a))
#define sign(a) (((a)<(0)) ? -1 : (a)>0 ? 1 : 0)
/* Addition and subtraction */
#define fpadd(a,b) ((a)+(b))
#define fpsub(a,b) ((a)-(b))
/* Multiplication */
#define fpmul(a,b) ((fp_t) ((((fpdbl_t)(a)) * ((fpdbl_t)(b))) >> N))
/* Division (a/b) */
#define fpdiv(a,b) ((fp_t) ((((fpdbl_t)a)<<N) / b))
/* Multiplication and division (v*m)/d */
#define fpmuldiv(v,m,d) ((fp_t)((((fpdbl_t)(v)) * ((fpdbl_t)(m))) / d))
/* Integer to fixed point and vice versa */
#define int2fp(a) (((fp_t)a)<<N)
#define fp2int(a) ((x)>>N)
/* Floating point to fixed point and vice versa */
#define float2fp(a) ((fp_t)((a) * (1<<N)))
#define fp2float(a) (((float)(a)) / (1<<N))
/* Extract the fractional part */
#define fpfract(x) ((x) & NMASK)