math_defs.h 822 B

1234567891011121314151617181920212223242526272829303132
  1. #ifndef AL_MATH_DEFS_H
  2. #define AL_MATH_DEFS_H
  3. #include <math.h>
  4. #ifndef M_PI
  5. #define M_PI 3.14159265358979323846
  6. #endif
  7. constexpr inline float Deg2Rad(float x) noexcept { return x * static_cast<float>(M_PI/180.0); }
  8. constexpr inline float Rad2Deg(float x) noexcept { return x * static_cast<float>(180.0/M_PI); }
  9. namespace al {
  10. template<typename Real>
  11. struct MathDefs { };
  12. template<>
  13. struct MathDefs<float> {
  14. static constexpr inline float Pi() noexcept { return static_cast<float>(M_PI); }
  15. static constexpr inline float Tau() noexcept { return static_cast<float>(M_PI * 2.0); }
  16. };
  17. template<>
  18. struct MathDefs<double> {
  19. static constexpr inline double Pi() noexcept { return M_PI; }
  20. static constexpr inline double Tau() noexcept { return M_PI * 2.0; }
  21. };
  22. } // namespace al
  23. #endif /* AL_MATH_DEFS_H */