my_math.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #ifndef __MY_MATH_H_
  2. #define __MY_MATH_H_
  3. #include "stdint.h"
  4. #define BIT_REVERSED(data) \
  5. ({ \
  6. typeof(data) _result = 0; \
  7. for(uint8_t i = 0; i < sizeof(typeof(data)) * 8; i++) \
  8. { \
  9. _result = ((data >> i) & 0x01) | _result; \
  10. if(i < (sizeof(typeof(data)) * 8 - 1)) \
  11. { \
  12. _result = _result << 1; \
  13. } \
  14. } \
  15. _result; \
  16. })
  17. #define MAX(x, y) \
  18. ({ \
  19. typeof(x) _max1 = (x); \
  20. typeof(y) _max2 = (y); \
  21. (void)(&_max1 == &_max2); \
  22. _max1 > _max2 ? _max1 : _max2 \
  23. })
  24. #define MIN(x, y) \
  25. ({ \
  26. typeof(x) _min1 = x; \
  27. typeof(y) _min2 = y; \
  28. (void)(&_min1 == &_min2); \
  29. _min1 < _min2 ? _min1 : _min2 \
  30. })
  31. #define OVER_WEIGHT_SCALE 1.2f/9.8f //假设a = 1.2
  32. #define LOSS_WEIGHT_SCALE -1.2f/9.8f
  33. void Least_Squares(uint8_t n, float x[], uint32_t y[], float* slope, float* intercept);
  34. void buf2int(int *tint, unsigned char *buf);
  35. float average(int n_values, ...);
  36. // uint8_t Bit_Reversed(uint8_t data);
  37. #endif