hpm_mcl_math.h 929 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * Copyright (c) 2023 HPMicro
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef HPM_MCL_MATH_H
  8. #define HPM_MCL_MATH_H
  9. #include "hpm_mcl_cfg.h"
  10. #ifndef HPM_MCL_MATH_HARDWARE_ACC
  11. #include <math.h>
  12. #endif
  13. /**
  14. * @brief Determine if a floating point number is 0
  15. *
  16. */
  17. #define MCL_FLOAT_IS_ZERO(val) ((val < 0.000001f) && (val > -0.000001f))
  18. #define MCL_FLOAT_IS_INFINITY(val) ((val == INFINITY) || (val == -INFINITY))
  19. #define SQRT3 (1.7320508075688773f) /**< sqrt(3) */
  20. #define SQRT3_DIV3 (0.5773502691896258f) /**< sqrt(3)/3 */
  21. #define MCL_SUM_OF_SQUARE_MODE(a, b) sqrtf((float)((a * a) + (b * b)))
  22. /**
  23. * @brief Enable Q format
  24. *
  25. */
  26. #ifndef HPM_MCL_Q_EN
  27. typedef float hpm_mcl_type_t;
  28. #define MCL_MATH_IS_ZERO(x) MCL_FLOAT_IS_ZERO((x))
  29. #define MCL_MATH_CONVERT_FLOAT(x) (x)
  30. #else
  31. typedef int32_t hpm_mcl_type_t;
  32. #define MCL_MATH_IS_ZERO(x) (x == 0)
  33. #define MCL_MATH_CONVERT_FLOAT(x) (x)
  34. #endif
  35. #endif