commit 1ff9d5c98ecf30a0fc7d9625b14dadb4f388bb18
parent 1f9706197abfcd4b4ec19ded3ce37b70ebd9a223
Author: [email protected] <[email protected]>
Date: Wed, 7 Oct 2020 22:17:47 +0100
Fix carg and tests
Diffstat:
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/include/kfr/math/complex_math.hpp b/include/kfr/math/complex_math.hpp
@@ -79,7 +79,7 @@ template <typename T, size_t N>
KFR_INTRINSIC vec<T, N> carg(const vec<complex<T>, N>& x)
{
const vec<T, N* 2> xx = cdecom(x);
- return atan2(even(xx), odd(xx));
+ return atan2(odd(xx), even(xx));
}
template <typename T, size_t N>
diff --git a/tests/complex_test.cpp b/tests/complex_test.cpp
@@ -6,6 +6,7 @@
#include <kfr/testo/testo.hpp>
+#include <complex>
#include <kfr/base.hpp>
#include <kfr/io.hpp>
@@ -93,6 +94,11 @@ TEST(complex_math)
CHECK(cabs(-3.f) == 3.f);
CHECK(cabs(make_vector(-3.f)) == make_vector(3.f));
+ CHECK(carg(c32{ +1.f, 0.f }) == 0.f);
+ CHECK(carg(c32{ 0.f, +1.f }) == c_pi<float> / 2);
+ CHECK(carg(c32{ 0.f, -1.f }) == -c_pi<float> / 2);
+ CHECK(carg(c32{ -1.f, 0.f }) == c_pi<float>);
+
testo::eplison_scope<void> eps(5);
CHECK(csin(c32{ 1.f, 1.f }) == c32{ 1.2984575814159773f, 0.634963914784736f });