From 1bbea9cd3060ef65a2623f156b4f12ebf62c52fe Mon Sep 17 00:00:00 2001
From: Chris Robinson <chris.kcat@gmail.com>
Date: Thu, 27 Jan 2022 01:38:39 -0800
Subject: Start and use a standard-like numbers header

---
 common/alcomplex.cpp |  4 ++--
 common/alnumbers.h   | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 2 deletions(-)
 create mode 100644 common/alnumbers.h

(limited to 'common')

diff --git a/common/alcomplex.cpp b/common/alcomplex.cpp
index 5cb35f38..6d2b18c1 100644
--- a/common/alcomplex.cpp
+++ b/common/alcomplex.cpp
@@ -10,8 +10,8 @@
 #include <utility>
 
 #include "albit.h"
+#include "alnumbers.h"
 #include "alnumeric.h"
-#include "math_defs.h"
 #include "opthelpers.h"
 
 
@@ -123,7 +123,7 @@ void complex_fft(const al::span<std::complex<double>> buffer, const double sign)
     size_t step2{1u};
     for(size_t i{0};i < log2_size;++i)
     {
-        const double arg{al::MathDefs<double>::Pi() / static_cast<double>(step2)};
+        const double arg{al::numbers::pi / static_cast<double>(step2)};
 
         const std::complex<double> w{std::cos(arg), std::sin(arg)*sign};
         std::complex<double> u{1.0, 0.0};
diff --git a/common/alnumbers.h b/common/alnumbers.h
new file mode 100644
index 00000000..98994b44
--- /dev/null
+++ b/common/alnumbers.h
@@ -0,0 +1,32 @@
+#ifndef COMMON_ALNUMBERS_H
+#define COMMON_ALNUMBERS_H
+
+#include <utility>
+
+namespace al {
+
+namespace numbers {
+
+namespace detail_ {
+    template<typename T>
+    using as_fp = std::enable_if_t<std::is_floating_point<T>::value, T>;
+} // detail_
+
+template<typename T>
+static constexpr auto pi_v = detail_::as_fp<T>(3.141592653589793238462643383279502884L);
+
+template<typename T>
+static constexpr auto inv_pi_v = detail_::as_fp<T>(0.318309886183790671537767526745028724L);
+
+template<typename T>
+static constexpr auto sqrt3_v = detail_::as_fp<T>(1.732050807568877293527446341505872367L);
+
+static constexpr auto pi = pi_v<double>;
+static constexpr auto inv_pi = inv_pi_v<double>;
+static constexpr auto sqrt3 = sqrt3_v<double>;
+
+} // namespace numbers
+
+} // namespace al
+
+#endif /* COMMON_ALNUMBERS_H */
-- 
cgit v1.2.3