From 90e9a33e1ce3e4e7663dd67e6c1f225afaf5c206 Mon Sep 17 00:00:00 2001 From: Antonio Sanchez Date: Fri, 7 May 2021 08:24:32 -0700 Subject: Fix numext::arg return type. The cxx11 path for `numext::arg` incorrectly returned the complex type instead of the real type, leading to compile errors. Fixed this and added tests. Related to !477, which uncovered the issue. --- test/numext.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'test/numext.cpp') diff --git a/test/numext.cpp b/test/numext.cpp index cf1ca173d..8a2fde501 100644 --- a/test/numext.cpp +++ b/test/numext.cpp @@ -61,6 +61,20 @@ void check_abs() { } } +template +void check_arg() { + typedef typename NumTraits::Real Real; + VERIFY_IS_EQUAL(numext::abs(T(0)), T(0)); + VERIFY_IS_EQUAL(numext::abs(T(1)), T(1)); + + for(int k=0; k<100; ++k) + { + T x = internal::random(); + Real y = numext::arg(x); + VERIFY_IS_APPROX( y, std::arg(x) ); + } +} + template struct check_sqrt_impl { static void run() { @@ -242,10 +256,12 @@ EIGEN_DECLARE_TEST(numext) { CALL_SUBTEST( check_abs() ); CALL_SUBTEST( check_abs() ); CALL_SUBTEST( check_abs() ); - CALL_SUBTEST( check_abs >() ); CALL_SUBTEST( check_abs >() ); + CALL_SUBTEST( check_arg >() ); + CALL_SUBTEST( check_arg >() ); + CALL_SUBTEST( check_sqrt() ); CALL_SUBTEST( check_sqrt() ); CALL_SUBTEST( check_sqrt >() ); -- cgit v1.2.3