diff options
author | Antonio Sanchez <cantonios@google.com> | 2021-05-07 08:24:32 -0700 |
---|---|---|
committer | Rasmus Munk Larsen <rmlarsen@google.com> | 2021-05-07 16:26:57 +0000 |
commit | 90e9a33e1ce3e4e7663dd67e6c1f225afaf5c206 (patch) | |
tree | cee0ab2ff0da2c4785a9a97546b206933869fc9e /test | |
parent | 722ca0b665666f3af579002ad752541d7319d1b6 (diff) |
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.
Diffstat (limited to 'test')
-rw-r--r-- | test/numext.cpp | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/test/numext.cpp b/test/numext.cpp index cf1ca173d..8a2fde501 100644 --- a/test/numext.cpp +++ b/test/numext.cpp @@ -62,6 +62,20 @@ void check_abs() { } template<typename T> +void check_arg() { + typedef typename NumTraits<T>::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<T>(); + Real y = numext::arg(x); + VERIFY_IS_APPROX( y, std::arg(x) ); + } +} + +template<typename T> struct check_sqrt_impl { static void run() { for (int i=0; i<1000; ++i) { @@ -242,10 +256,12 @@ EIGEN_DECLARE_TEST(numext) { CALL_SUBTEST( check_abs<float>() ); CALL_SUBTEST( check_abs<double>() ); CALL_SUBTEST( check_abs<long double>() ); - CALL_SUBTEST( check_abs<std::complex<float> >() ); CALL_SUBTEST( check_abs<std::complex<double> >() ); + CALL_SUBTEST( check_arg<std::complex<float> >() ); + CALL_SUBTEST( check_arg<std::complex<double> >() ); + CALL_SUBTEST( check_sqrt<float>() ); CALL_SUBTEST( check_sqrt<double>() ); CALL_SUBTEST( check_sqrt<std::complex<float> >() ); |