math_defs.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #ifndef AL_MATH_DEFS_H
  2. #define AL_MATH_DEFS_H
  3. #include <math.h>
  4. #ifdef HAVE_FLOAT_H
  5. #include <float.h>
  6. #endif
  7. #ifndef M_PI
  8. #define M_PI (3.14159265358979323846)
  9. #endif
  10. #define F_PI (3.14159265358979323846f)
  11. #define F_PI_2 (1.57079632679489661923f)
  12. #define F_TAU (6.28318530717958647692f)
  13. #ifndef FLT_EPSILON
  14. #define FLT_EPSILON (1.19209290e-07f)
  15. #endif
  16. #define SQRT_2 1.41421356237309504880
  17. #define SQRT_3 1.73205080756887719318
  18. #define SQRTF_2 1.41421356237309504880f
  19. #define SQRTF_3 1.73205080756887719318f
  20. #ifndef HUGE_VALF
  21. static const union msvc_inf_hack {
  22. unsigned char b[4];
  23. float f;
  24. } msvc_inf_union = {{ 0x00, 0x00, 0x80, 0x7F }};
  25. #define HUGE_VALF (msvc_inf_union.f)
  26. #endif
  27. #ifndef HAVE_LOG2F
  28. static inline float log2f(float f)
  29. {
  30. return logf(f) / logf(2.0f);
  31. }
  32. #endif
  33. #ifndef HAVE_CBRTF
  34. static inline float cbrtf(float f)
  35. {
  36. return powf(f, 1.0f/3.0f);
  37. }
  38. #endif
  39. #ifndef HAVE_COPYSIGNF
  40. static inline float copysignf(float x, float y)
  41. {
  42. union {
  43. float f;
  44. unsigned int u;
  45. } ux = { x }, uy = { y };
  46. ux.u &= 0x7fffffffu;
  47. ux.u |= (uy.u&0x80000000u);
  48. return ux.f;
  49. }
  50. #endif
  51. #define DEG2RAD(x) ((float)(x) * (float)(M_PI/180.0))
  52. #define RAD2DEG(x) ((float)(x) * (float)(180.0/M_PI))
  53. #endif /* AL_MATH_DEFS_H */