mlmath.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. $License:
  3. Copyright (C) 2011 InvenSense Corporation, All Rights Reserved.
  4. $
  5. */
  6. /*******************************************************************************
  7. *
  8. * $Id: mlmath.h 5629 2011-06-11 03:13:08Z mcaramello $
  9. *
  10. *******************************************************************************/
  11. #ifndef _ML_MATH_H_
  12. #define _ML_MATH_H_
  13. #ifndef MLMATH
  14. // This define makes Microsoft pickup things like M_PI
  15. #define _USE_MATH_DEFINES
  16. #include <math.h>
  17. #ifdef WIN32
  18. // Microsoft doesn't follow standards
  19. #define round(x)(((double)((long long)((x)>0?(x)+.5:(x)-.5))))
  20. #define roundf(x)(((float )((long long)((x)>0?(x)+.5f:(x)-.5f))))
  21. #endif
  22. #else // MLMATH
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. /* MPL needs below functions */
  27. double ml_asin(double);
  28. double ml_atan(double);
  29. double ml_atan2(double, double);
  30. double ml_log(double);
  31. double ml_sqrt(double);
  32. double ml_ceil(double);
  33. double ml_floor(double);
  34. double ml_cos(double);
  35. double ml_sin(double);
  36. double ml_acos(double);
  37. #ifdef __cplusplus
  38. } // extern "C"
  39. #endif
  40. /*
  41. * We rename functions here to provide the hook for other
  42. * customized math functions.
  43. */
  44. #define sqrt(x) ml_sqrt(x)
  45. #define log(x) ml_log(x)
  46. #define asin(x) ml_asin(x)
  47. #define atan(x) ml_atan(x)
  48. #define atan2(x,y) ml_atan2(x,y)
  49. #define ceil(x) ml_ceil(x)
  50. #define floor(x) ml_floor(x)
  51. #define fabs(x) (((x)<0)?-(x):(x))
  52. #define round(x) (((double)((long long)((x)>0?(x)+.5:(x)-.5))))
  53. #define roundf(x) (((float )((long long)((x)>0?(x)+.5f:(x)-.5f))))
  54. #define cos(x) ml_cos(x)
  55. #define sin(x) ml_sin(x)
  56. #define acos(x) ml_acos(x)
  57. #define pow(x,y) ml_pow(x,y)
  58. #ifdef LINUX
  59. /* stubs for float version of math functions */
  60. #define cosf(x) ml_cos(x)
  61. #define sinf(x) ml_sin(x)
  62. #define atan2f(x,y) ml_atan2(x,y)
  63. #define sqrtf(x) ml_sqrt(x)
  64. #endif
  65. #endif // MLMATH
  66. #ifndef M_PI
  67. #define M_PI 3.14159265358979
  68. #endif
  69. #ifndef ABS
  70. #define ABS(x) (((x)>=0)?(x):-(x))
  71. #endif
  72. #ifndef MIN
  73. #define MIN(x,y) (((x)<(y))?(x):(y))
  74. #endif
  75. #ifndef MAX
  76. #define MAX(x,y) (((x)>(y))?(x):(y))
  77. #endif
  78. /*---------------------------*/
  79. #endif /* !_ML_MATH_H_ */