Extract some constexpr math utilities to utility.hpp

...my dumping ground for so many random bits.
This commit is contained in:
Jared Boone 2016-02-10 10:15:42 -08:00
parent 096e961c67
commit dfbcf5bc75
2 changed files with 9 additions and 8 deletions

View file

@ -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<float> c) {