From dfbcf5bc752a08bd9df8f19c5a5b6db6a6b519a7 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Wed, 10 Feb 2016 10:15:42 -0800 Subject: [PATCH] Extract some constexpr math utilities to utility.hpp ...my dumping ground for so many random bits. --- firmware/common/dsp_fft.hpp | 9 +-------- firmware/common/utility.hpp | 8 ++++++++ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/firmware/common/dsp_fft.hpp b/firmware/common/dsp_fft.hpp index a360721a..65dd8098 100644 --- a/firmware/common/dsp_fft.hpp +++ b/firmware/common/dsp_fft.hpp @@ -32,6 +32,7 @@ #include "dsp_types.hpp" #include "complex.hpp" #include "hal.h" +#include "utility.hpp" namespace std { /* https://github.com/AE9RB/fftbench/blob/master/cxlr.hpp @@ -47,14 +48,6 @@ namespace std { } } /* namespace std */ -constexpr bool power_of_two(const size_t n) { - return (n & (n - 1)) == 0; -} - -constexpr size_t log_2(const size_t n, const size_t p = 0) { - return (n <= 1) ? p : log_2(n / 2, p + 1); -} - template void fft_swap(const buffer_c16_t src, std::array& dst) { static_assert(power_of_two(N), "only defined for N == power of two"); diff --git a/firmware/common/utility.hpp b/firmware/common/utility.hpp index 2a2dc9f4..02caa1a1 100644 --- a/firmware/common/utility.hpp +++ b/firmware/common/utility.hpp @@ -61,6 +61,14 @@ inline constexpr T pow(const T base, unsigned const exponent) { return (exponent == 0) ? 1 : (base * pow(base, exponent - 1)); } +constexpr bool power_of_two(const size_t n) { + return (n & (n - 1)) == 0; +} + +constexpr size_t log_2(const size_t n, const size_t p = 0) { + return (n <= 1) ? p : log_2(n / 2, p + 1); +} + float complex16_mag_squared_to_dbv_norm(const float c16_mag_squared); inline float magnitude_squared(const std::complex c) {