From f8ac1ffe805b13c8b1cd2bc4d4a8362cbe1c2cbe Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Thu, 27 Jan 2022 02:59:07 -0800 Subject: Get rid of MathDefs --- common/alnumbers.h | 4 ++++ common/math_defs.h | 23 ++--------------------- common/polyphase_resampler.cpp | 8 ++++---- 3 files changed, 10 insertions(+), 25 deletions(-) (limited to 'common') diff --git a/common/alnumbers.h b/common/alnumbers.h index 98994b44..37a55410 100644 --- a/common/alnumbers.h +++ b/common/alnumbers.h @@ -18,11 +18,15 @@ static constexpr auto pi_v = detail_::as_fp(3.1415926535897932384626433832795 template static constexpr auto inv_pi_v = detail_::as_fp(0.318309886183790671537767526745028724L); +template +static constexpr auto sqrt2_v = detail_::as_fp(1.414213562373095048801688724209698079L); + template static constexpr auto sqrt3_v = detail_::as_fp(1.732050807568877293527446341505872367L); static constexpr auto pi = pi_v; static constexpr auto inv_pi = inv_pi_v; +static constexpr auto sqrt2 = sqrt2_v; static constexpr auto sqrt3 = sqrt3_v; } // namespace numbers diff --git a/common/math_defs.h b/common/math_defs.h index ba007115..d66923ea 100644 --- a/common/math_defs.h +++ b/common/math_defs.h @@ -1,26 +1,7 @@ #ifndef AL_MATH_DEFS_H #define AL_MATH_DEFS_H -constexpr float Deg2Rad(float x) noexcept { return x * 1.74532925199432955e-02f/*pi/180*/; } -constexpr float Rad2Deg(float x) noexcept { return x * 5.72957795130823229e+01f/*180/pi*/; } - -namespace al { - -template -struct MathDefs { }; - -template<> -struct MathDefs { - static constexpr float Pi() noexcept { return 3.14159265358979323846e+00f; } - static constexpr float Tau() noexcept { return 6.28318530717958647692e+00f; } -}; - -template<> -struct MathDefs { - static constexpr double Pi() noexcept { return 3.14159265358979323846e+00; } - static constexpr double Tau() noexcept { return 6.28318530717958647692e+00; } -}; - -} // namespace al +constexpr float Deg2Rad(float x) noexcept +{ return static_cast(x * 1.74532925199432955e-02/*pi/180*/); } #endif /* AL_MATH_DEFS_H */ diff --git a/common/polyphase_resampler.cpp b/common/polyphase_resampler.cpp index 88c4bc4b..bb8f69a4 100644 --- a/common/polyphase_resampler.cpp +++ b/common/polyphase_resampler.cpp @@ -4,7 +4,7 @@ #include #include -#include "math_defs.h" +#include "alnumbers.h" #include "opthelpers.h" @@ -21,9 +21,9 @@ using uint = unsigned int; */ double Sinc(const double x) { - if UNLIKELY(std::abs(x) < Epsilon) + if(unlikely(std::abs(x) < Epsilon)) return 1.0; - return std::sin(al::MathDefs::Pi()*x) / (al::MathDefs::Pi()*x); + return std::sin(al::numbers::pi*x) / (al::numbers::pi*x); } /* The zero-order modified Bessel function of the first kind, used for the @@ -95,7 +95,7 @@ constexpr uint Gcd(uint x, uint y) */ constexpr uint CalcKaiserOrder(const double rejection, const double transition) { - const double w_t{2.0 * al::MathDefs::Pi() * transition}; + const double w_t{2.0 * al::numbers::pi * transition}; if LIKELY(rejection > 21.0) return static_cast(std::ceil((rejection - 7.95) / (2.285 * w_t))); return static_cast(std::ceil(5.79 / w_t)); -- cgit v1.2.3