diff --git a/lerp.cpp b/lerp.cpp index d0fa7802..b1dfd8dd 100644 --- a/lerp.cpp +++ b/lerp.cpp @@ -42,7 +42,7 @@ lerp::linear (double a, double b, double weight) { double lerp::cosine (double a, double b, double weight) { CHECK (weight >= 0.0 && weight <= 1.0); - double t = (1.0 - cos (weight * PI_d)) * 0.5; + double t = (1.0 - cos (weight * PI)) * 0.5; return a * (1.0 - t) + b * t; } diff --git a/maths.hpp b/maths.hpp index f2fa6f3c..07fd92f3 100644 --- a/maths.hpp +++ b/maths.hpp @@ -171,19 +171,17 @@ exactly_zero [[gnu::pure]] (T a) // angles, trig template -struct constants { }; +constexpr T PI = T(3.141592653589793238462643); -constexpr double PI_d = 3.141592653589793238462643; -constexpr float PI_f = 3.141592653589793238462643f; +template +constexpr T E = T(2.71828182845904523536028747135266250); -constexpr float E_f = 2.71828182845904523536028747135266250f; -constexpr double E_d = 2.71828182845904523536028747135266250; template constexpr T to_degrees [[gnu::pure]] (T radians) { - return radians * 180 / constants::PI; + return radians * 180 / PI; } @@ -191,7 +189,7 @@ template constexpr T to_radians [[gnu::pure]] (T degrees) { - return degrees / 180 * constants::PI; + return degrees / 180 * PI; } @@ -200,7 +198,7 @@ template constexpr T sincn [[gnu::pure]] (T x) { - return almost_zero (x) ? 1 : std::sin (constants::PI * x) / (constants::PI * x); + return almost_zero (x) ? 1 : std::sin (PI * x) / (PI * x); } @@ -224,7 +222,7 @@ factorial [[gnu::pure]] (unsigned i) constexpr uintmax_t stirling [[gnu::pure]] (unsigned n) { - return static_cast (std::sqrt (2 * PI_f * n) * std::pow (n / E_f, n)); + return static_cast (std::sqrt (2 * PI * n) * std::pow (n / E, n)); } diff --git a/maths.ipp b/maths.ipp index 2f3e1dc6..72e328f3 100644 --- a/maths.ipp +++ b/maths.ipp @@ -66,20 +66,3 @@ sign (double v) { return std::signbit (v) ? -1. : 1.f; } - - -//----------------------------------------------------------------------------- -template <> -struct constants -{ - static constexpr float PI = PI_f; - static constexpr float E = E_f; -}; - - -template <> -struct constants -{ - static constexpr double PI = PI_d; - static constexpr double E = E_d; -}; diff --git a/polynomial.cpp b/polynomial.cpp index c794e09c..0334f6b6 100644 --- a/polynomial.cpp +++ b/polynomial.cpp @@ -116,8 +116,8 @@ namespace util { namespace polynomial { const float t = 2 * std::sqrt (-p); s[0] = t * std::cos (phi); - s[1] = -t * std::cos (phi + PI_f / 3.f); - s[2] = -t * std::cos (phi - PI_f / 3.f); + s[1] = -t * std::cos (phi + PI / 3.f); + s[2] = -t * std::cos (phi - PI / 3.f); } else { float u = std::cbrt (std::sqrt (D) + abs (q)); if (q > 0.f) diff --git a/test/maths.cpp b/test/maths.cpp index 8f44990f..dfc34c79 100644 --- a/test/maths.cpp +++ b/test/maths.cpp @@ -114,10 +114,10 @@ main (int, char **) { CHECK_EQ (sign ( numeric_limits::infinity ()), 1); CHECK_EQ (sign (-numeric_limits::infinity ()), -1); - CHECK_EQ (to_degrees (PI_d), 180.0); - CHECK_EQ (to_degrees (PI_f), 180.f); - CHECK_EQ (to_radians (180.f), PI_f); - CHECK_EQ (to_radians (180.0), PI_d); + CHECK_EQ (to_degrees (PI), 180.0); + CHECK_EQ (to_degrees (PI), 180.f); + CHECK_EQ (to_radians (180.f), PI); + CHECK_EQ (to_radians (180.0), PI); CHECK_EQ (log2 (8u), 3); CHECK_EQ (log2 (1u), 0); diff --git a/test/vector.cpp b/test/vector.cpp index ad160bf5..74610194 100644 --- a/test/vector.cpp +++ b/test/vector.cpp @@ -28,13 +28,13 @@ test_polar (void) }, { - { 1.f, PI_f / 2.f }, + { 1.f, PI / 2.f }, { 0.f, 1.f }, "unit length, rotated" }, { - { 1.f, 2 * PI_f }, + { 1.f, 2 * PI }, { 1.f, 0.f }, "full rotation, unit length" } @@ -53,8 +53,8 @@ test_polar (void) auto in_polar = t.polar; auto to_polar = util::cartesian_to_polar (t.cartesian); - in_polar[1] = std::fmod (in_polar[1], 2 * PI_f); - to_polar[1] = std::fmod (to_polar[1], 2 * PI_f); + in_polar[1] = std::fmod (in_polar[1], 2 * PI); + to_polar[1] = std::fmod (to_polar[1], 2 * PI); CHECK_EQ (in_polar, to_polar); }