From 51779c68eba4d6be99e211c5b4fb599784173b40 Mon Sep 17 00:00:00 2001 From: Andrey Davydov Date: Fri, 12 Jun 2015 17:14:30 +0300 Subject: [PATCH] + runtime check of rounding mode support For example, following program #include int main() { boost::numeric::interval::traits_type::rounding _; } will work fine if is built with gcc using '-frounding-math', but will fail otherwise. Running on Valgrind is another practical case when this program will crash (even if it was correctly built). --- .../boost/numeric/interval/hw_rounding.hpp | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/include/boost/numeric/interval/hw_rounding.hpp b/include/boost/numeric/interval/hw_rounding.hpp index 574b243..4330aba 100644 --- a/include/boost/numeric/interval/hw_rounding.hpp +++ b/include/boost/numeric/interval/hw_rounding.hpp @@ -11,6 +11,8 @@ #ifndef BOOST_NUMERIC_INTERVAL_HW_ROUNDING_HPP #define BOOST_NUMERIC_INTERVAL_HW_ROUNDING_HPP +#include + #include #include @@ -46,6 +48,31 @@ namespace boost { namespace numeric { namespace interval_lib { +namespace detail +{ + template + struct runtime_checker + { + protected: + runtime_checker() + { + static helper _; + } + + private: + struct helper + { + helper() + { + save_state > rounding; + T a = -(T(-1.1) * T(10.1)); + T b = +(T(+1.1) * T(10.1)); + assert(a != b); + } + }; + }; +} + /* * Three specializations of rounded_math */ @@ -53,16 +80,19 @@ namespace interval_lib { template<> struct rounded_math : save_state > + , private detail::runtime_checker {}; template<> struct rounded_math : save_state > + , private detail::runtime_checker {}; template<> struct rounded_math : save_state > + , private detail::runtime_checker {}; } // namespace interval_lib