my_math.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #ifndef __MY_MATH_H
  2. #define __MY_MATH_H
  3. #include <stdbool.h>
  4. #include <stdint.h>
  5. #define M_PI_F 3.14159265358979f //圆周率
  6. #ifndef M_2PI_F
  7. #define M_2PI_F (2 * M_PI_F)
  8. #endif
  9. #define EARTH_R 6378100 //地球半径(m)
  10. // acceleration due to gravity in m/s/s
  11. #define GRAVITY_MSS 9.80665f
  12. // acceleration due to gravity in cm/s/s
  13. #define GRAVITY_CMSS 980.665f
  14. // Single precision conversions
  15. #define DEG_TO_RAD 0.017453292519943295769236907684886f // 度换算弧度
  16. #define RAD_TO_DEG 57.295779513082320876798154814105f // 弧度换算度
  17. // convert a longitude or latitude point to meters or centimeteres.
  18. // Note: this does not include the longitude scaling which is dependent upon
  19. // location
  20. #define LONLAT_TO_M 0.01113195f
  21. #define LONLAT_TO_CM 1.113195f
  22. #define max(a, b) \
  23. ({ \
  24. typeof(a) _a = (a); \
  25. typeof(b) _b = (b); \
  26. _a > _b ? _a : _b; \
  27. })
  28. #define min(a, b) \
  29. ({ \
  30. typeof(a) _a = (a); \
  31. typeof(b) _b = (b); \
  32. _a < _b ? _a : _b; \
  33. })
  34. void buf2float(float *tfloat, unsigned char *buf);
  35. void buf2long(long *tfloat, unsigned char *buf);
  36. void buf2int(int *tint, unsigned char *buf);
  37. void buf2short(short *tshort, unsigned char *buf);
  38. void float2buf(unsigned char *buf, float *tfloat);
  39. void int2buf(unsigned char *buf, int *tint);
  40. void short2buf(unsigned char *buf, short *tshort);
  41. int brinv(float a[], int n);
  42. // constrain a int16_t value
  43. int16_t constrain_int16(int16_t amt, int16_t low, int16_t high);
  44. // constrain a int32_t value
  45. int32_t constrain_int32(int32_t amt, int32_t low, int32_t high);
  46. unsigned char constrain_uint8(unsigned char value, unsigned char min,
  47. unsigned char max);
  48. short math_constrain(short value, short min, short max);
  49. short abs_int16(short value);
  50. float min_float(float value1, float value2);
  51. int min_int32(int value1, int value2);
  52. short min_int16(short value1, short value2);
  53. float max_float(float value1, float value2);
  54. int max_int32(int value1, int value2);
  55. short max_int16(short value1, short value2);
  56. bool is_zero(const float fVal1);
  57. float no_zero_float(float Val1);
  58. int no_zero_int32(int Val1);
  59. float sq(float v);
  60. float get_norm(float a, float b);
  61. // float stdev(short num[], int n);
  62. void insert_sort(int arr[], int n);
  63. #endif