diff options
author | Miao Wang <miaowang@google.com> | 2017-07-06 22:13:27 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2017-07-06 22:13:27 +0000 |
commit | c905f05b1b1277cc5b913652b2d4a57da12b89f7 (patch) | |
tree | 28a6fbea7c5a1e9a0f1a209f8d33e6d72f1df851 /test/numext.cpp | |
parent | cfefb1dc11c33fb8a74291cf2b08e3aa49cb879a (diff) | |
parent | eda03298de395cf6217486971e6529f92da8da79 (diff) | |
download | eigen-c905f05b1b1277cc5b913652b2d4a57da12b89f7.tar.gz |
Merge "Rebase Eigen to 3.3.4"
Diffstat (limited to 'test/numext.cpp')
-rw-r--r-- | test/numext.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/test/numext.cpp b/test/numext.cpp new file mode 100644 index 000000000..3de33e2f9 --- /dev/null +++ b/test/numext.cpp @@ -0,0 +1,53 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2017 Gael Guennebaud <gael.guennebaud@inria.fr> +// +// This Source Code Form is subject to the terms of the Mozilla +// Public License v. 2.0. If a copy of the MPL was not distributed +// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include "main.h" + +template<typename T> +void check_abs() { + typedef typename NumTraits<T>::Real Real; + + if(NumTraits<T>::IsSigned) + VERIFY_IS_EQUAL(numext::abs(-T(1)), T(1)); + VERIFY_IS_EQUAL(numext::abs(T(0)), T(0)); + VERIFY_IS_EQUAL(numext::abs(T(1)), T(1)); + + for(int k=0; k<g_repeat*100; ++k) + { + T x = internal::random<T>(); + if(!internal::is_same<T,bool>::value) + x = x/Real(2); + if(NumTraits<T>::IsSigned) + { + VERIFY_IS_EQUAL(numext::abs(x), numext::abs(-x)); + VERIFY( numext::abs(-x) >= Real(0)); + } + VERIFY( numext::abs(x) >= Real(0)); + VERIFY_IS_APPROX( numext::abs2(x), numext::abs2(numext::abs(x)) ); + } +} + +void test_numext() { + CALL_SUBTEST( check_abs<bool>() ); + CALL_SUBTEST( check_abs<signed char>() ); + CALL_SUBTEST( check_abs<unsigned char>() ); + CALL_SUBTEST( check_abs<short>() ); + CALL_SUBTEST( check_abs<unsigned short>() ); + CALL_SUBTEST( check_abs<int>() ); + CALL_SUBTEST( check_abs<unsigned int>() ); + CALL_SUBTEST( check_abs<long>() ); + CALL_SUBTEST( check_abs<unsigned long>() ); + CALL_SUBTEST( check_abs<half>() ); + 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> >() ); +} |