From 781dd9f0f22fde5a4e51cf3b72274a7c69e85aa0 Mon Sep 17 00:00:00 2001 From: Robert Ramey Date: Wed, 10 Mar 2021 11:41:15 -0800 Subject: [PATCH] =?UTF-8?q?some=20tests=20use=20math/special=20functions?= =?UTF-8?q?=20to=20compare=20floating=20point=20numbers=20used=20generated?= =?UTF-8?q?=20by=20test=20results.=20=20math/special=20functions=20recentl?= =?UTF-8?q?y=20changed=20so=20now=20it=20requires=20C++11=20or=20above.=20?= =?UTF-8?q?=20=20That=20is,=20usage=20under=20C++03=20and=20less=20is=20de?= =?UTF-8?q?precated.=20=20In=20order=20to=20continue=20to=20support=20the?= =?UTF-8?q?=20serialization=20library=20in=20C++03=20and=20later=20I=20had?= =?UTF-8?q?=20to=20make=20some=20changes.=20=20After=20looking=20at=20the?= =?UTF-8?q?=20alternatives,=20I=20decide=20just=20to=20suppress=20some=20t?= =?UTF-8?q?ests=20related=20to=20floating=20point=20numbers.=20=20Overall,?= =?UTF-8?q?=20even=20though=20it=20skips=20over=20some=20tests=20for=20C++?= =?UTF-8?q?03=20platforms,=20it=20was=20the=20easiest=20to=20implement.=20?= =?UTF-8?q?=20C++03=20is=20not=20widely=20used=20these=20days=20so=20it=20?= =?UTF-8?q?wasn=E2=80=99t=20worth=20the=20effort=20to=20replace=20reliance?= =?UTF-8?q?=20on=20math/special=20functions.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/A.cpp | 16 +++++++++++----- test/test_complex.cpp | 20 ++++++++++++-------- test/test_non_default_ctor.cpp | 23 ++++++++++++++--------- test/test_non_intrusive.cpp | 18 ++++++++++++------ test/test_simple_class.cpp | 10 +++++++--- test/test_variant.cpp | 18 +++++++++++++++--- 6 files changed, 71 insertions(+), 34 deletions(-) diff --git a/test/A.cpp b/test/A.cpp index 332505ff..7a8033f4 100644 --- a/test/A.cpp +++ b/test/A.cpp @@ -11,9 +11,12 @@ #include #include // rand() #include // size_t -#include + #include +#if BOOST_CXX_VERSION > 199711L // only include floating point if C++ version >= C++11 +#include +#endif #if defined(BOOST_NO_STDC_NAMESPACE) namespace std{ using ::rand; @@ -148,11 +151,14 @@ A::operator==(const A &rhs) const { return false; if(v != rhs.v) return false; - if(std::abs( boost::math::float_distance(w, rhs.w)) > 1) - return false; - if(std::abs( boost::math::float_distance(x, rhs.x)) > 1) - return false; + #if BOOST_CXX_VERSION > 199711L // only include floating point if C++ version >= C++11 + if(std::abs( boost::math::float_distance(w, rhs.w)) > 1) + return false; + if(std::abs( boost::math::float_distance(x, rhs.x)) > 1) + return false; + #endif if(0 != y.compare(rhs.y)) + return false; #ifndef BOOST_NO_STD_WSTRING if(0 != z.compare(rhs.z)) diff --git a/test/test_complex.cpp b/test/test_complex.cpp index 7caca871..6ba5618a 100644 --- a/test/test_complex.cpp +++ b/test/test_complex.cpp @@ -15,7 +15,9 @@ #include // remove #include #include +#if BOOST_CXX_VERSION > 199711L // only include floating point if C++ version >= C++11 #include +#endif #if defined(BOOST_NO_STDC_NAMESPACE) #include @@ -66,14 +68,16 @@ int test_main( int /* argc */, char* /* argv */[] ) ia >> boost::serialization::make_nvp("adoublecomplex", b1); } - std::cerr << "a.real()-a1a.real() distance = " << std::abs( boost::math::float_distance(a.real(), a1.real())) << std::endl; - BOOST_CHECK(std::abs(boost::math::float_distance(a.real(), a1.real())) < 2); - std::cerr << "a.imag() - a1a.imag() distance = " << std::abs( boost::math::float_distance(a.imag(), a1.imag())) << std::endl; - BOOST_CHECK(std::abs(boost::math::float_distance(a.imag(), a1.imag())) < 2); - std::cerr << "b.real() - b1.real() distance = " << std::abs( boost::math::float_distance(b.real(), b1.real())) << std::endl; - BOOST_CHECK(std::abs(boost::math::float_distance(b.real(), b1.real())) < 2); - std::cerr << "b.imag() - b1.imag() distance = " << std::abs( boost::math::float_distance(b.imag(), b1.imag())) << std::endl; - BOOST_CHECK(std::abs(boost::math::float_distance(b.imag(), b1.imag())) < 2); + #if BOOST_CXX_VERSION > 199711L // only include floating point if C++ version >= C++11 + std::cerr << "a.real()-a1a.real() distance = " << std::abs( boost::math::float_distance(a.real(), a1.real())) << std::endl; + BOOST_CHECK(std::abs(boost::math::float_distance(a.real(), a1.real())) < 2); + std::cerr << "a.imag() - a1a.imag() distance = " << std::abs( boost::math::float_distance(a.imag(), a1.imag())) << std::endl; + BOOST_CHECK(std::abs(boost::math::float_distance(a.imag(), a1.imag())) < 2); + std::cerr << "b.real() - b1.real() distance = " << std::abs( boost::math::float_distance(b.real(), b1.real())) << std::endl; + BOOST_CHECK(std::abs(boost::math::float_distance(b.real(), b1.real())) < 2); + std::cerr << "b.imag() - b1.imag() distance = " << std::abs( boost::math::float_distance(b.imag(), b1.imag())) << std::endl; + BOOST_CHECK(std::abs(boost::math::float_distance(b.imag(), b1.imag())) < 2); + #endif std::remove(testfile); return EXIT_SUCCESS; diff --git a/test/test_non_default_ctor.cpp b/test/test_non_default_ctor.cpp index 33780ce8..e2450503 100644 --- a/test/test_non_default_ctor.cpp +++ b/test/test_non_default_ctor.cpp @@ -19,8 +19,9 @@ #include #include #include +#if BOOST_CXX_VERSION > 199711L // only include floating point if C++ version >= C++11 #include - +#endif #if defined(BOOST_NO_STDC_NAMESPACE) namespace std{ using ::rand; @@ -99,12 +100,14 @@ bool A::operator==(const A &rhs) const && t == rhs.t && u == rhs.u && v == rhs.v - && std::abs( boost::math::float_distance(w, rhs.w)) < 2 - && std::abs( boost::math::float_distance(x, rhs.x)) < 2 - ; + #if BOOST_CXX_VERSION > 199711L // only include floating point if C++ version >= C++11 + && std::abs( boost::math::float_distance(w, rhs.w)) < 2 + && std::abs( boost::math::float_distance(x, rhs.x)) < 2 + #endif + ; } -bool A::operator<(const A &rhs) const + bool A::operator<(const A &rhs) const { if(! (s == rhs.s) ) return s < rhs.s; @@ -114,10 +117,12 @@ bool A::operator<(const A &rhs) const return t < rhs.u; if(! (v == rhs.v) ) return t < rhs.v; - if(std::abs( boost::math::float_distance(w, rhs.w)) > 1) - return false; - if(std::abs( boost::math::float_distance(x, rhs.x)) > 1) - return false; + #if BOOST_CXX_VERSION > 199711L // only include floating point if C++ version >= C++11 + if(std::abs( boost::math::float_distance(w, rhs.w)) > 1) + return false; + if(std::abs( boost::math::float_distance(x, rhs.x)) > 1) + return false; + #endif return false; } diff --git a/test/test_non_intrusive.cpp b/test/test_non_intrusive.cpp index b3c3536c..c1d8a746 100644 --- a/test/test_non_intrusive.cpp +++ b/test/test_non_intrusive.cpp @@ -18,7 +18,9 @@ #include #include #include +#if BOOST_CXX_VERSION > 199711L // only include floating point if C++ version >= C++11 #include +#endif #if defined(BOOST_NO_STDC_NAMESPACE) namespace std{ @@ -67,8 +69,10 @@ bool A::operator==(const A &rhs) const && t == rhs.t && u == rhs.u && v == rhs.v - && std::abs( boost::math::float_distance(w, rhs.w)) < 2 - && std::abs( boost::math::float_distance(x, rhs.x)) < 2 + #if BOOST_CXX_VERSION > 199711L // only include floating point if C++ version >= C++11 + && std::abs( boost::math::float_distance(w, rhs.w)) < 2 + && std::abs( boost::math::float_distance(x, rhs.x)) < 2 + #endif ; } @@ -82,10 +86,12 @@ bool A::operator<(const A &rhs) const return t < rhs.u; if(! (v == rhs.v) ) return t < rhs.v; - if(std::abs( boost::math::float_distance(w, rhs.w)) > 1) - return false; - if(std::abs( boost::math::float_distance(x, rhs.x)) > 1) - return false; + #if BOOST_CXX_VERSION > 199711L // only include floating point if C++ version >= C++11 + if(std::abs( boost::math::float_distance(w, rhs.w)) > 1) + return false; + if(std::abs( boost::math::float_distance(x, rhs.x)) > 1) + return false; + #endif return false; } diff --git a/test/test_simple_class.cpp b/test/test_simple_class.cpp index 41c8cb21..ac0c19f7 100644 --- a/test/test_simple_class.cpp +++ b/test/test_simple_class.cpp @@ -14,9 +14,11 @@ #include // remove #include #include -#include #include +#if BOOST_CXX_VERSION > 199711L // only include floating point if C++ version >= C++11 +#include +#endif #if defined(BOOST_NO_STDC_NAMESPACE) namespace std{ @@ -51,8 +53,10 @@ bool A::check_equal(const A &rhs) const BOOST_CHECK_EQUAL(u, rhs.u); BOOST_CHECK_EQUAL(v, rhs.v); BOOST_CHECK_EQUAL(l, rhs.l); - BOOST_CHECK(std::abs( boost::math::float_distance(w, rhs.w)) < 2); - BOOST_CHECK(std::abs( boost::math::float_distance(x, rhs.x)) < 2); + #if BOOST_CXX_VERSION > 199711L // only include floating point if C++ version >= C++11 + BOOST_CHECK(std::abs( boost::math::float_distance(w, rhs.w)) < 2); + BOOST_CHECK(std::abs( boost::math::float_distance(x, rhs.x)) < 2); + #endif BOOST_CHECK(!(0 != y.compare(rhs.y))); #ifndef BOOST_NO_STD_WSTRING BOOST_CHECK(!(0 != z.compare(rhs.z))); diff --git a/test/test_variant.cpp b/test/test_variant.cpp index dcf91d13..8154b3bf 100644 --- a/test/test_variant.cpp +++ b/test/test_variant.cpp @@ -18,8 +18,12 @@ #include // NULL #include // remove #include + #include -#include // float_distance +#if BOOST_CXX_VERSION > 199711L // only include floating point if C++ version >= C++11 +#include +#endif + #if defined(BOOST_NO_STDC_NAMESPACE) namespace std{ using ::remove; @@ -77,11 +81,19 @@ public: bool operator()( const float & lhs, const float & rhs ) const { - return std::abs( boost::math::float_distance(lhs, rhs)) < 2; + #if BOOST_CXX_VERSION > 199711L // only include floating point if C++ version >= C++11 + return std::abs( boost::math::float_distance(w, rhs.w) ) < 2; + #else + return true; + #endif } bool operator()( const double & lhs, const double & rhs ) const { - return std::abs( boost::math::float_distance(lhs, rhs)) < 2; + #if BOOST_CXX_VERSION > 199711L // only include floating point if C++ version >= C++11 + return std::abs( boost::math::float_distance(w, rhs.w) ) < 2; + #else + return true; + #endif } };