kfr

Fast, modern C++ DSP framework, FFT, Sample Rate Conversion, FIR/IIR/Biquad Filters (SSE, AVX, AVX-512, ARM NEON)
Log | Files | Refs | README

commit 1d834c1c26f7fcb816f13eaeb1a86b98768566be
parent 365a8f93534cc4e9e0da7d66a7dc08fb9907ca09
Author: [email protected] <[email protected]>
Date:   Mon, 12 Sep 2016 19:12:02 +0300

Implement cabs and carg for real numbers

Diffstat:
Minclude/kfr/base/complex.hpp | 15+++++++++++++++
Minclude/kfr/base/expression.hpp | 2+-
Mtests/complex_test.cpp | 3+++
3 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/include/kfr/base/complex.hpp b/include/kfr/base/complex.hpp @@ -254,6 +254,11 @@ constexpr CMT_INLINE vec<T, N * 2> cdecom(const vec<complex<T>, N>& x) return compcast<T>(x); } +template <typename T, KFR_ENABLE_IF(is_numeric<T>::value)> +constexpr CMT_INLINE T real(const T& value) +{ + return value; +} template <typename T> constexpr CMT_INLINE T real(const complex<T>& value) { @@ -414,6 +419,16 @@ KFR_I_CONVERTER(polar) KFR_I_CONVERTER(cartesian) KFR_I_CONVERTER(csqrt) +template <typename T, size_t N> +KFR_SINTRIN vec<T, N> cabs(const vec<T, N>& a) +{ + return to_scalar(intrinsics::cabs(static_cast<vec<complex<T>, N>>(a))); +} +template <typename T, size_t N> +KFR_SINTRIN vec<T, N> carg(const vec<T, N>& a) +{ + return to_scalar(intrinsics::carg(static_cast<vec<complex<T>, N>>(a))); +} template <typename T1> KFR_SINTRIN realtype<T1> cabs(const T1& a) { diff --git a/include/kfr/base/expression.hpp b/include/kfr/base/expression.hpp @@ -372,7 +372,7 @@ CMT_INLINE size_t process(OutputExpr&& out, const InputExpr& in, size_t start = static_assert(is_output_expression<OutputExpr>::value, "OutFn must be an expression"); static_assert(is_input_expression<InputExpr>::value, "Fn must be an expression"); - size = size_sub(size_min(out.size(), in.size(), size_add(size, start)), start); + size = size_sub(size_min(out.size(), in.size(), size_add(size, start)), start); if (size == 0 || size == infinite_size) return size; const size_t end = start + size; diff --git a/tests/complex_test.cpp b/tests/complex_test.cpp @@ -80,6 +80,9 @@ TEST(complex_math) CHECK(cabs(c32{ 3.f, 4.f }) == 5.f); CHECK(cabs(make_vector(c32{ 3.f, 4.f })) == make_vector(5.f)); + CHECK(cabs(-3.f) == 3.f); + CHECK(cabs(make_vector(-3.f)) == make_vector(3.f)); + testo::epsilon<f32>() *= 5; testo::epsilon<f64>() *= 5;