diff --git a/include/math_util.h b/include/math_util.h index 948d501033..0dd11c230b 100644 --- a/include/math_util.h +++ b/include/math_util.h @@ -8,6 +8,19 @@ #ifndef __CROS_EC_MATH_UTIL_H #define __CROS_EC_MATH_UTIL_H +#ifdef CONFIG_FPU +typedef float fp_t; +typedef float fp_inter_t; + +/* Conversion to/from fixed-point */ +#define INT_TO_FP(x) ((float)(x)) +#define FP_TO_INT(x) ((int32_t)(x)) +/* Float to fixed-point, only for compile-time constants and unit tests */ +#define FLOAT_TO_FP(x) ((float)(x)) +/* Fixed-point to float, for unit tests */ +#define FP_TO_FLOAT(x) ((float)(x)) + +#else /* Fixed-point type */ typedef int32_t fp_t; @@ -24,12 +37,24 @@ typedef int64_t fp_inter_t; #define FLOAT_TO_FP(x) ((fp_t)((x) * (float)(1<= 0 ? a : -a); + return (a >= INT_TO_FP(0) ? a : -a); } /*