diff options
author | Sven Gothel <[email protected]> | 2019-12-12 19:21:00 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2019-12-12 19:21:00 +0100 |
commit | 4df06c6894b39af5bf4681c0acf0c1c080084c80 (patch) | |
tree | 2505eb6e3b5798db34033c4cac2d4613bf6bda44 /common/math_defs.h | |
parent | 8915501ed02eac2b3bce9a7fc06cb1ab562901c3 (diff) | |
parent | c0cf323e1d56ce605e90927324d2fdafcfbb564a (diff) |
merge v1.20.0
Diffstat (limited to 'common/math_defs.h')
-rw-r--r-- | common/math_defs.h | 67 |
1 files changed, 17 insertions, 50 deletions
diff --git a/common/math_defs.h b/common/math_defs.h index aa79b695..0362a956 100644 --- a/common/math_defs.h +++ b/common/math_defs.h @@ -2,64 +2,31 @@ #define AL_MATH_DEFS_H #include <math.h> -#ifdef HAVE_FLOAT_H -#include <float.h> -#endif #ifndef M_PI -#define M_PI (3.14159265358979323846) +#define M_PI 3.14159265358979323846 #endif -#define F_PI (3.14159265358979323846f) -#define F_PI_2 (1.57079632679489661923f) -#define F_TAU (6.28318530717958647692f) +constexpr inline float Deg2Rad(float x) noexcept { return x * static_cast<float>(M_PI/180.0); } +constexpr inline float Rad2Deg(float x) noexcept { return x * static_cast<float>(180.0/M_PI); } -#ifndef FLT_EPSILON -#define FLT_EPSILON (1.19209290e-07f) -#endif +namespace al { -#define SQRT_2 1.41421356237309504880 -#define SQRT_3 1.73205080756887719318 +template<typename Real> +struct MathDefs { }; -#define SQRTF_2 1.41421356237309504880f -#define SQRTF_3 1.73205080756887719318f +template<> +struct MathDefs<float> { + static constexpr inline float Pi() noexcept { return static_cast<float>(M_PI); } + static constexpr inline float Tau() noexcept { return static_cast<float>(M_PI * 2.0); } +}; -#ifndef HUGE_VALF -static const union msvc_inf_hack { - unsigned char b[4]; - float f; -} msvc_inf_union = {{ 0x00, 0x00, 0x80, 0x7F }}; -#define HUGE_VALF (msvc_inf_union.f) -#endif - -#ifndef HAVE_LOG2F -static inline float log2f(float f) -{ - return logf(f) / logf(2.0f); -} -#endif - -#ifndef HAVE_CBRTF -static inline float cbrtf(float f) -{ - return powf(f, 1.0f/3.0f); -} -#endif - -#ifndef HAVE_COPYSIGNF -static inline float copysignf(float x, float y) -{ - union { - float f; - unsigned int u; - } ux = { x }, uy = { y }; - ux.u &= 0x7fffffffu; - ux.u |= (uy.u&0x80000000u); - return ux.f; -} -#endif +template<> +struct MathDefs<double> { + static constexpr inline double Pi() noexcept { return M_PI; } + static constexpr inline double Tau() noexcept { return M_PI * 2.0; } +}; -#define DEG2RAD(x) ((float)(x) * (float)(M_PI/180.0)) -#define RAD2DEG(x) ((float)(x) * (float)(180.0/M_PI)) +} // namespace al #endif /* AL_MATH_DEFS_H */ |