math_defs.h 871 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. #ifndef HUGE_VALF
  17. static const union msvc_inf_hack {
  18. unsigned char b[4];
  19. float f;
  20. } msvc_inf_union = {{ 0x00, 0x00, 0x80, 0x7F }};
  21. #define HUGE_VALF (msvc_inf_union.f)
  22. #endif
  23. #ifndef HAVE_LOG2F
  24. static inline float log2f(float f)
  25. {
  26. return logf(f) / logf(2.0f);
  27. }
  28. #endif
  29. #ifndef HAVE_CBRTF
  30. static inline float cbrtf(float f)
  31. {
  32. return powf(f, 1.0f/3.0f);
  33. }
  34. #endif
  35. #define DEG2RAD(x) ((float)(x) * (F_PI/180.0f))
  36. #define RAD2DEG(x) ((float)(x) * (180.0f/F_PI))
  37. #endif /* AL_MATH_DEFS_H */