11 #ifndef CH_MATH_UTILS_H_
12 #define CH_MATH_UTILS_H_
24 #define INT2FIXED(x) ((x) << FRACT_BITS)
25 #define FLOAT2FIXED(x) ((fixed_t)((x) * (1 << FRACT_BITS)))
27 #define FIXED2INT(x) ((x) >> FRACT_BITS)
28 #define FIXED2FLOAT(x) (((float)(x)) / (1 << FRACT_BITS))
30 #define FIXEDDIV(x, y) ((fixed_t)(((uint64_t)(x) << FRACT_BITS) / (y)))
31 #define FIXEDMUL(x, y) ((fixed_t)(((x) >> (FRACT_BITS / 2)) * ((y) >> (FRACT_BITS / 2))))
33 #define FIXED_PI 0x3243FU
35 #define INV_LOG2_E_Q1DOT31 0x58b90bfcU
37 #define Q31_TO_Q16_SHIFT_BITS 15
38 #define Q31_TO_Q16_SHIFT_1 10
39 #define Q31_TO_Q16_SHIFT_2 (Q31_TO_Q16_SHIFT_BITS - Q31_TO_Q16_SHIFT_1)
42 typedef uint32_t fixed_t;
44 fixed_t FP_sqrt(fixed_t x);
int32_t sqrt_int32(int32_t v)
Compute the square root of a 32-bit integer.
Definition: ch_math_utils.c:84
fixed_t FP_log(fixed_t x)
Find the natural logarithm in UQ16.16 fixed-point format.
Definition: ch_math_utils.c:64
fixed_t FP_log2(fixed_t x)
Find the base 2 logarithm in UQ16.16 fixed-point format.
Definition: ch_math_utils.c:34