sl@0: /* Boost interval/checking.hpp template implementation file sl@0: * sl@0: * Copyright 2002 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion sl@0: * sl@0: * Distributed under the Boost Software License, Version 1.0. sl@0: * (See accompanying file LICENSE_1_0.txt or sl@0: * copy at http://www.boost.org/LICENSE_1_0.txt) sl@0: */ sl@0: sl@0: #ifndef BOOST_NUMERIC_INTERVAL_CHECKING_HPP sl@0: #define BOOST_NUMERIC_INTERVAL_CHECKING_HPP sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: namespace boost { sl@0: namespace numeric { sl@0: namespace interval_lib { sl@0: sl@0: struct exception_create_empty sl@0: { sl@0: void operator()() sl@0: { sl@0: throw std::runtime_error("boost::interval: empty interval created"); sl@0: } sl@0: }; sl@0: sl@0: struct exception_invalid_number sl@0: { sl@0: void operator()() sl@0: { sl@0: throw std::invalid_argument("boost::interval: invalid number"); sl@0: } sl@0: }; sl@0: sl@0: template sl@0: struct checking_base sl@0: { sl@0: static T pos_inf() sl@0: { sl@0: assert(std::numeric_limits::has_infinity); sl@0: return std::numeric_limits::infinity(); sl@0: } sl@0: static T neg_inf() sl@0: { sl@0: assert(std::numeric_limits::has_infinity); sl@0: return -std::numeric_limits::infinity(); sl@0: } sl@0: static T nan() sl@0: { sl@0: assert(std::numeric_limits::has_quiet_NaN); sl@0: return std::numeric_limits::quiet_NaN(); sl@0: } sl@0: static bool is_nan(const T& x) sl@0: { sl@0: return std::numeric_limits::has_quiet_NaN && (x != x); sl@0: } sl@0: static T empty_lower() sl@0: { sl@0: return (std::numeric_limits::has_quiet_NaN ? sl@0: std::numeric_limits::quiet_NaN() : static_cast(1)); sl@0: } sl@0: static T empty_upper() sl@0: { sl@0: return (std::numeric_limits::has_quiet_NaN ? sl@0: std::numeric_limits::quiet_NaN() : static_cast(0)); sl@0: } sl@0: static bool is_empty(const T& l, const T& u) sl@0: { sl@0: return !(l <= u); // safety for partial orders sl@0: } sl@0: }; sl@0: sl@0: template, sl@0: class Exception = exception_create_empty> sl@0: struct checking_no_empty: Checking sl@0: { sl@0: static T nan() sl@0: { sl@0: assert(false); sl@0: return Checking::nan(); sl@0: } sl@0: static T empty_lower() sl@0: { sl@0: Exception()(); sl@0: return Checking::empty_lower(); sl@0: } sl@0: static T empty_upper() sl@0: { sl@0: Exception()(); sl@0: return Checking::empty_upper(); sl@0: } sl@0: static bool is_empty(const T&, const T&) sl@0: { sl@0: return false; sl@0: } sl@0: }; sl@0: sl@0: template > sl@0: struct checking_no_nan: Checking sl@0: { sl@0: static bool is_nan(const T&) sl@0: { sl@0: return false; sl@0: } sl@0: }; sl@0: sl@0: template, sl@0: class Exception = exception_invalid_number> sl@0: struct checking_catch_nan: Checking sl@0: { sl@0: static bool is_nan(const T& x) sl@0: { sl@0: if (Checking::is_nan(x)) Exception()(); sl@0: return false; sl@0: } sl@0: }; sl@0: sl@0: template sl@0: struct checking_strict: sl@0: checking_no_nan > sl@0: {}; sl@0: sl@0: } // namespace interval_lib sl@0: } // namespace numeric sl@0: } // namespace boost sl@0: sl@0: #endif // BOOST_NUMERIC_INTERVAL_CHECKING_HPP