diff options
author | Chris Robinson <[email protected]> | 2019-01-06 04:16:51 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2019-01-06 04:16:51 -0800 |
commit | da3a916042a7ba9426af1d6f03e689dbd7760191 (patch) | |
tree | ab6cfc0d2fd26504a013989af7ecd399a4034914 /common | |
parent | 98f3e6a16295029129193a073680a70c034703dd (diff) |
Replace macros with constexpr inline functions
Diffstat (limited to 'common')
-rw-r--r-- | common/math_defs.h | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/common/math_defs.h b/common/math_defs.h index 6471e2e7..9749bd53 100644 --- a/common/math_defs.h +++ b/common/math_defs.h @@ -4,16 +4,31 @@ #include <math.h> #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) - -#define SQRTF_3 1.73205080756887719318f - 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); } +namespace al { + +template<typename Real> +struct MathDefs { }; + +template<> +struct MathDefs<float> { + static constexpr inline float Pi() noexcept { return 3.14159265358979323846f; } + static constexpr inline float Tau() noexcept { return 3.14159265358979323846f * 2.0f; } + static constexpr inline float Sqrt3() noexcept { return 1.73205080756887719318f; } +}; + +template<> +struct MathDefs<double> { + static constexpr inline double Pi() noexcept { return 3.14159265358979323846; } + static constexpr inline double Tau() noexcept { return 3.14159265358979323846 * 2.0; } + static constexpr inline double Sqrt3() noexcept { return 1.73205080756887719318; } +}; + +} // namespace al + #endif /* AL_MATH_DEFS_H */ |