// Copyright John Maddock 2007. // Use, modification and distribution are subject to the // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_MATH_POLICY_HPP #define BOOST_MATH_POLICY_HPP #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // Sadly we do need the .h versions of these to be sure of getting // FLT_MANT_DIG etc. #include #include #include #include namespace boost{ namespace math{ namespace tools{ template int digits(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(T)); template T epsilon(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(T)); } namespace policies{ // // Define macros for our default policies, if they're not defined already: // #ifndef BOOST_MATH_DOMAIN_ERROR_POLICY #define BOOST_MATH_DOMAIN_ERROR_POLICY throw_on_error #endif #ifndef BOOST_MATH_POLE_ERROR_POLICY #define BOOST_MATH_POLE_ERROR_POLICY throw_on_error #endif #ifndef BOOST_MATH_OVERFLOW_ERROR_POLICY #define BOOST_MATH_OVERFLOW_ERROR_POLICY throw_on_error #endif #ifndef BOOST_MATH_EVALUATION_ERROR_POLICY #define BOOST_MATH_EVALUATION_ERROR_POLICY throw_on_error #endif #ifndef BOOST_MATH_ROUNDING_ERROR_POLICY #define BOOST_MATH_ROUNDING_ERROR_POLICY throw_on_error #endif #ifndef BOOST_MATH_UNDERFLOW_ERROR_POLICY #define BOOST_MATH_UNDERFLOW_ERROR_POLICY ignore_error #endif #ifndef BOOST_MATH_DENORM_ERROR_POLICY #define BOOST_MATH_DENORM_ERROR_POLICY ignore_error #endif #ifndef BOOST_MATH_INDETERMINATE_RESULT_ERROR_POLICY #define BOOST_MATH_INDETERMINATE_RESULT_ERROR_POLICY ignore_error #endif #ifndef BOOST_MATH_DIGITS10_POLICY #define BOOST_MATH_DIGITS10_POLICY 0 #endif #ifndef BOOST_MATH_PROMOTE_FLOAT_POLICY #define BOOST_MATH_PROMOTE_FLOAT_POLICY true #endif #ifndef BOOST_MATH_PROMOTE_DOUBLE_POLICY #ifdef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS #define BOOST_MATH_PROMOTE_DOUBLE_POLICY false #else #define BOOST_MATH_PROMOTE_DOUBLE_POLICY true #endif #endif #ifndef BOOST_MATH_DISCRETE_QUANTILE_POLICY #define BOOST_MATH_DISCRETE_QUANTILE_POLICY integer_round_outwards #endif #ifndef BOOST_MATH_ASSERT_UNDEFINED_POLICY #define BOOST_MATH_ASSERT_UNDEFINED_POLICY true #endif #ifndef BOOST_MATH_MAX_SERIES_ITERATION_POLICY #define BOOST_MATH_MAX_SERIES_ITERATION_POLICY 1000000 #endif #ifndef BOOST_MATH_MAX_ROOT_ITERATION_POLICY #define BOOST_MATH_MAX_ROOT_ITERATION_POLICY 200 #endif #if !defined(__BORLANDC__) \ && !(defined(__GNUC__) && (__GNUC__ == 3) && (__GNUC_MINOR__ <= 2)) #define BOOST_MATH_META_INT(type, name, Default)\ template struct name : public boost::mpl::int_{};\ namespace detail{\ template \ char test_is_valid_arg(const name*);\ char test_is_default_arg(const name*);\ template struct is_##name##_imp\ {\ template static char test(const name*);\ static double test(...);\ BOOST_STATIC_CONSTANT(bool, value = sizeof(test(static_cast(0))) == 1);\ };\ }\ template struct is_##name : public boost::mpl::bool_< ::boost::math::policies::detail::is_##name##_imp::value>{}; #define BOOST_MATH_META_BOOL(name, Default)\ template struct name : public boost::mpl::bool_{};\ namespace detail{\ template \ char test_is_valid_arg(const name*);\ char test_is_default_arg(const name*);\ template struct is_##name##_imp\ {\ template static char test(const name*);\ static double test(...);\ BOOST_STATIC_CONSTANT(bool, value = sizeof(test(static_cast(0))) == 1);\ };\ }\ template struct is_##name : public boost::mpl::bool_< ::boost::math::policies::detail::is_##name##_imp::value>{}; #else #define BOOST_MATH_META_INT(Type, name, Default)\ template struct name : public boost::mpl::int_{};\ namespace detail{\ template \ char test_is_valid_arg(const name*);\ char test_is_default_arg(const name*);\ template struct is_##name##_tester\ {\ template static char test(const name&);\ static double test(...);\ };\ template struct is_##name##_imp\ {\ static T inst;\ BOOST_STATIC_CONSTANT(bool, value = sizeof( ::boost::math::policies::detail::is_##name##_tester::test(inst)) == 1);\ };\ }\ template struct is_##name : public boost::mpl::bool_< ::boost::math::policies::detail::is_##name##_imp::value>\ {\ template struct apply{ typedef is_##name type; };\ }; #define BOOST_MATH_META_BOOL(name, Default)\ template struct name : public boost::mpl::bool_{};\ namespace detail{\ template \ char test_is_valid_arg(const name*);\ char test_is_default_arg(const name*);\ template struct is_##name##_tester\ {\ template static char test(const name&);\ static double test(...);\ };\ template struct is_##name##_imp\ {\ static T inst;\ BOOST_STATIC_CONSTANT(bool, value = sizeof( ::boost::math::policies::detail::is_##name##_tester::test(inst)) == 1);\ };\ }\ template struct is_##name : public boost::mpl::bool_< ::boost::math::policies::detail::is_##name##_imp::value>\ {\ template struct apply{ typedef is_##name type; };\ }; #endif // // Begin by defining policy types for error handling: // enum error_policy_type { throw_on_error = 0, errno_on_error = 1, ignore_error = 2, user_error = 3 }; BOOST_MATH_META_INT(error_policy_type, domain_error, BOOST_MATH_DOMAIN_ERROR_POLICY) BOOST_MATH_META_INT(error_policy_type, pole_error, BOOST_MATH_POLE_ERROR_POLICY) BOOST_MATH_META_INT(error_policy_type, overflow_error, BOOST_MATH_OVERFLOW_ERROR_POLICY) BOOST_MATH_META_INT(error_policy_type, underflow_error, BOOST_MATH_UNDERFLOW_ERROR_POLICY) BOOST_MATH_META_INT(error_policy_type, denorm_error, BOOST_MATH_DENORM_ERROR_POLICY) BOOST_MATH_META_INT(error_policy_type, evaluation_error, BOOST_MATH_EVALUATION_ERROR_POLICY) BOOST_MATH_META_INT(error_policy_type, rounding_error, BOOST_MATH_ROUNDING_ERROR_POLICY) BOOST_MATH_META_INT(error_policy_type, indeterminate_result_error, BOOST_MATH_INDETERMINATE_RESULT_ERROR_POLICY) // // Policy types for internal promotion: // BOOST_MATH_META_BOOL(promote_float, BOOST_MATH_PROMOTE_FLOAT_POLICY) BOOST_MATH_META_BOOL(promote_double, BOOST_MATH_PROMOTE_DOUBLE_POLICY) BOOST_MATH_META_BOOL(assert_undefined, BOOST_MATH_ASSERT_UNDEFINED_POLICY) // // Policy types for discrete quantiles: // enum discrete_quantile_policy_type { real, integer_round_outwards, integer_round_inwards, integer_round_down, integer_round_up, integer_round_nearest }; BOOST_MATH_META_INT(discrete_quantile_policy_type, discrete_quantile, BOOST_MATH_DISCRETE_QUANTILE_POLICY) // // Precision: // BOOST_MATH_META_INT(int, digits10, BOOST_MATH_DIGITS10_POLICY) BOOST_MATH_META_INT(int, digits2, 0) // // Iterations: // BOOST_MATH_META_INT(unsigned long, max_series_iterations, BOOST_MATH_MAX_SERIES_ITERATION_POLICY) BOOST_MATH_META_INT(unsigned long, max_root_iterations, BOOST_MATH_MAX_ROOT_ITERATION_POLICY) // // Define the names for each possible policy: // #define BOOST_MATH_PARAMETER(name)\ BOOST_PARAMETER_TEMPLATE_KEYWORD(name##_name)\ BOOST_PARAMETER_NAME(name##_name) struct default_policy{}; namespace detail{ // // Trait to work out bits precision from digits10 and digits2: // template struct precision { // // Now work out the precision: // typedef typename mpl::if_c< (Digits10::value == 0), digits2<0>, digits2<((Digits10::value + 1) * 1000L) / 301L> >::type digits2_type; public: #ifdef __BORLANDC__ typedef typename mpl::if_c< (Digits2::value > ::boost::math::policies::detail::precision::digits2_type::value), Digits2, digits2_type>::type type; #else typedef typename mpl::if_c< (Digits2::value > digits2_type::value), Digits2, digits2_type>::type type; #endif }; template struct select_result { typedef A type; }; template struct select_result { typedef typename mpl::deref::type type; }; template struct find_arg { private: typedef typename mpl::find_if::type iter; typedef typename mpl::end::type end_type; public: typedef typename select_result< DefaultType, iter, ::boost::is_same::value>::type type; }; double test_is_valid_arg(...); double test_is_default_arg(...); char test_is_valid_arg(const default_policy*); char test_is_default_arg(const default_policy*); template struct is_valid_policy_imp { BOOST_STATIC_CONSTANT(bool, value = sizeof(::boost::math::policies::detail::test_is_valid_arg(static_cast(0))) == 1); }; template struct is_default_policy_imp { BOOST_STATIC_CONSTANT(bool, value = sizeof(::boost::math::policies::detail::test_is_default_arg(static_cast(0))) == 1); }; template struct is_valid_policy : public mpl::bool_< ::boost::math::policies::detail::is_valid_policy_imp::value> {}; template struct is_default_policy : public mpl::bool_< ::boost::math::policies::detail::is_default_policy_imp::value> { template struct apply { typedef is_default_policy type; }; }; template struct append_N { typedef typename mpl::push_back::type new_seq; typedef typename append_N::type type; }; template struct append_N { typedef Seq type; }; // // Traits class to work out what template parameters our default // policy<> class will have when modified for forwarding: // template struct default_args { typedef promote_float arg1; typedef promote_double arg2; }; template <> struct default_args { typedef default_policy arg1; typedef default_policy arg2; }; template <> struct default_args { typedef promote_float arg1; typedef default_policy arg2; }; template <> struct default_args { typedef promote_double arg1; typedef default_policy arg2; }; typedef default_args::arg1 forwarding_arg1; typedef default_args::arg2 forwarding_arg2; } // detail // // Now define the policy type with enough arguments to handle all // the policies: // template struct policy { private: // // Validate all our arguments: // BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy::value); BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy::value); BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy::value); BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy::value); BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy::value); BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy::value); BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy::value); BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy::value); BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy::value); BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy::value); BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy::value); BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy::value); BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy::value); // // Typelist of the arguments: // typedef mpl::list arg_list; public: typedef typename detail::find_arg, domain_error<> >::type domain_error_type; typedef typename detail::find_arg, pole_error<> >::type pole_error_type; typedef typename detail::find_arg, overflow_error<> >::type overflow_error_type; typedef typename detail::find_arg, underflow_error<> >::type underflow_error_type; typedef typename detail::find_arg, denorm_error<> >::type denorm_error_type; typedef typename detail::find_arg, evaluation_error<> >::type evaluation_error_type; typedef typename detail::find_arg, rounding_error<> >::type rounding_error_type; typedef typename detail::find_arg, indeterminate_result_error<> >::type indeterminate_result_error_type; private: // // Now work out the precision: // typedef typename detail::find_arg, digits10<> >::type digits10_type; typedef typename detail::find_arg, digits2<> >::type bits_precision_type; public: typedef typename detail::precision::type precision_type; // // Internal promotion: // typedef typename detail::find_arg, promote_float<> >::type promote_float_type; typedef typename detail::find_arg, promote_double<> >::type promote_double_type; // // Discrete quantiles: // typedef typename detail::find_arg, discrete_quantile<> >::type discrete_quantile_type; // // Mathematically undefined properties: // typedef typename detail::find_arg, assert_undefined<> >::type assert_undefined_type; // // Max iterations: // typedef typename detail::find_arg, max_series_iterations<> >::type max_series_iterations_type; typedef typename detail::find_arg, max_root_iterations<> >::type max_root_iterations_type; }; // // These full specializations are defined to reduce the amount of // template instantiations that have to take place when using the default // policies, they have quite a large impact on compile times: // template <> struct policy { public: typedef domain_error<> domain_error_type; typedef pole_error<> pole_error_type; typedef overflow_error<> overflow_error_type; typedef underflow_error<> underflow_error_type; typedef denorm_error<> denorm_error_type; typedef evaluation_error<> evaluation_error_type; typedef rounding_error<> rounding_error_type; typedef indeterminate_result_error<> indeterminate_result_error_type; #if BOOST_MATH_DIGITS10_POLICY == 0 typedef digits2<> precision_type; #else typedef detail::precision, digits2<> >::type precision_type; #endif typedef promote_float<> promote_float_type; typedef promote_double<> promote_double_type; typedef discrete_quantile<> discrete_quantile_type; typedef assert_undefined<> assert_undefined_type; typedef max_series_iterations<> max_series_iterations_type; typedef max_root_iterations<> max_root_iterations_type; }; template <> struct policy { public: typedef domain_error<> domain_error_type; typedef pole_error<> pole_error_type; typedef overflow_error<> overflow_error_type; typedef underflow_error<> underflow_error_type; typedef denorm_error<> denorm_error_type; typedef evaluation_error<> evaluation_error_type; typedef rounding_error<> rounding_error_type; typedef indeterminate_result_error<> indeterminate_result_error_type; #if BOOST_MATH_DIGITS10_POLICY == 0 typedef digits2<> precision_type; #else typedef detail::precision, digits2<> >::type precision_type; #endif typedef promote_float promote_float_type; typedef promote_double promote_double_type; typedef discrete_quantile<> discrete_quantile_type; typedef assert_undefined<> assert_undefined_type; typedef max_series_iterations<> max_series_iterations_type; typedef max_root_iterations<> max_root_iterations_type; }; template struct normalise { private: typedef mpl::list arg_list; typedef typename detail::find_arg, typename Policy::domain_error_type >::type domain_error_type; typedef typename detail::find_arg, typename Policy::pole_error_type >::type pole_error_type; typedef typename detail::find_arg, typename Policy::overflow_error_type >::type overflow_error_type; typedef typename detail::find_arg, typename Policy::underflow_error_type >::type underflow_error_type; typedef typename detail::find_arg, typename Policy::denorm_error_type >::type denorm_error_type; typedef typename detail::find_arg, typename Policy::evaluation_error_type >::type evaluation_error_type; typedef typename detail::find_arg, typename Policy::rounding_error_type >::type rounding_error_type; typedef typename detail::find_arg, typename Policy::indeterminate_result_error_type >::type indeterminate_result_error_type; // // Now work out the precision: // typedef typename detail::find_arg, digits10<> >::type digits10_type; typedef typename detail::find_arg, typename Policy::precision_type >::type bits_precision_type; typedef typename detail::precision::type precision_type; // // Internal promotion: // typedef typename detail::find_arg, typename Policy::promote_float_type >::type promote_float_type; typedef typename detail::find_arg, typename Policy::promote_double_type >::type promote_double_type; // // Discrete quantiles: // typedef typename detail::find_arg, typename Policy::discrete_quantile_type >::type discrete_quantile_type; // // Mathematically undefined properties: // typedef typename detail::find_arg, typename Policy::assert_undefined_type >::type assert_undefined_type; // // Max iterations: // typedef typename detail::find_arg, typename Policy::max_series_iterations_type>::type max_series_iterations_type; typedef typename detail::find_arg, typename Policy::max_root_iterations_type>::type max_root_iterations_type; // // Define a typelist of the policies: // typedef mpl::vector< domain_error_type, pole_error_type, overflow_error_type, underflow_error_type, denorm_error_type, evaluation_error_type, rounding_error_type, indeterminate_result_error_type, precision_type, promote_float_type, promote_double_type, discrete_quantile_type, assert_undefined_type, max_series_iterations_type, max_root_iterations_type> result_list; // // Remove all the policies that are the same as the default: // typedef typename mpl::remove_if >::type reduced_list; // // Pad out the list with defaults: // typedef typename detail::append_N::value)>::type result_type; public: typedef policy< typename mpl::at >::type, typename mpl::at >::type, typename mpl::at >::type, typename mpl::at >::type, typename mpl::at >::type, typename mpl::at >::type, typename mpl::at >::type, typename mpl::at >::type, typename mpl::at >::type, typename mpl::at >::type, typename mpl::at >::type, typename mpl::at >::type, typename mpl::at >::type > type; }; // // Full specialisation to speed up compilation of the common case: // template <> struct normalise, promote_float, promote_double, discrete_quantile<>, assert_undefined<>, default_policy, default_policy, default_policy, default_policy, default_policy, default_policy, default_policy> { typedef policy type; }; template <> struct normalise, promote_float, promote_double, discrete_quantile<>, assert_undefined<>, default_policy, default_policy, default_policy, default_policy, default_policy, default_policy, default_policy> { typedef policy type; }; inline policy<> make_policy() { return policy<>(); } template inline typename normalise, A1>::type make_policy(const A1&) { typedef typename normalise, A1>::type result_type; return result_type(); } template inline typename normalise, A1, A2>::type make_policy(const A1&, const A2&) { typedef typename normalise, A1, A2>::type result_type; return result_type(); } template inline typename normalise, A1, A2, A3>::type make_policy(const A1&, const A2&, const A3&) { typedef typename normalise, A1, A2, A3>::type result_type; return result_type(); } template inline typename normalise, A1, A2, A3, A4>::type make_policy(const A1&, const A2&, const A3&, const A4&) { typedef typename normalise, A1, A2, A3, A4>::type result_type; return result_type(); } template inline typename normalise, A1, A2, A3, A4, A5>::type make_policy(const A1&, const A2&, const A3&, const A4&, const A5&) { typedef typename normalise, A1, A2, A3, A4, A5>::type result_type; return result_type(); } template inline typename normalise, A1, A2, A3, A4, A5, A6>::type make_policy(const A1&, const A2&, const A3&, const A4&, const A5&, const A6&) { typedef typename normalise, A1, A2, A3, A4, A5, A6>::type result_type; return result_type(); } template inline typename normalise, A1, A2, A3, A4, A5, A6, A7>::type make_policy(const A1&, const A2&, const A3&, const A4&, const A5&, const A6&, const A7&) { typedef typename normalise, A1, A2, A3, A4, A5, A6, A7>::type result_type; return result_type(); } template inline typename normalise, A1, A2, A3, A4, A5, A6, A7, A8>::type make_policy(const A1&, const A2&, const A3&, const A4&, const A5&, const A6&, const A7&, const A8&) { typedef typename normalise, A1, A2, A3, A4, A5, A6, A7, A8>::type result_type; return result_type(); } template inline typename normalise, A1, A2, A3, A4, A5, A6, A7, A8, A9>::type make_policy(const A1&, const A2&, const A3&, const A4&, const A5&, const A6&, const A7&, const A8&, const A9&) { typedef typename normalise, A1, A2, A3, A4, A5, A6, A7, A8, A9>::type result_type; return result_type(); } template inline typename normalise, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10>::type make_policy(const A1&, const A2&, const A3&, const A4&, const A5&, const A6&, const A7&, const A8&, const A9&, const A10&) { typedef typename normalise, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10>::type result_type; return result_type(); } template inline typename normalise, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11>::type make_policy(const A1&, const A2&, const A3&, const A4&, const A5&, const A6&, const A7&, const A8&, const A9&, const A10&, const A11&) { typedef typename normalise, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11>::type result_type; return result_type(); } // // Traits class to handle internal promotion: // template struct evaluation { typedef Real type; }; template struct evaluation { typedef typename mpl::if_::type type; }; template struct evaluation { typedef typename mpl::if_::type type; }; #ifdef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS template struct basic_digits : public mpl::int_<0>{ }; template <> struct basic_digits : public mpl::int_{ }; template <> struct basic_digits : public mpl::int_{ }; template <> struct basic_digits : public mpl::int_{ }; template struct precision { BOOST_STATIC_ASSERT( ::std::numeric_limits::radix == 2); typedef typename Policy::precision_type precision_type; typedef basic_digits digits_t; typedef typename mpl::if_< mpl::equal_to >, // Possibly unknown precision: precision_type, typename mpl::if_< mpl::or_, mpl::less_equal > >, // Default case, full precision for RealType: digits2< ::std::numeric_limits::digits>, // User customised precision: precision_type >::type >::type type; }; template struct precision { typedef digits2 type; }; template struct precision { typedef digits2 type; }; template struct precision { typedef digits2 type; }; #else template struct precision { BOOST_STATIC_ASSERT((::std::numeric_limits::radix == 2) || ((::std::numeric_limits::is_specialized == 0) || (::std::numeric_limits::digits == 0))); #ifndef __BORLANDC__ typedef typename Policy::precision_type precision_type; typedef typename mpl::if_c< ((::std::numeric_limits::is_specialized == 0) || (::std::numeric_limits::digits == 0)), // Possibly unknown precision: precision_type, typename mpl::if_c< ((::std::numeric_limits::digits <= precision_type::value) || (Policy::precision_type::value <= 0)), // Default case, full precision for RealType: digits2< ::std::numeric_limits::digits>, // User customised precision: precision_type >::type >::type type; #else typedef typename Policy::precision_type precision_type; typedef mpl::int_< ::std::numeric_limits::digits> digits_t; typedef mpl::bool_< ::std::numeric_limits::is_specialized> spec_t; typedef typename mpl::if_< mpl::or_, mpl::equal_to > >, // Possibly unknown precision: precision_type, typename mpl::if_< mpl::or_, mpl::less_equal > >, // Default case, full precision for RealType: digits2< ::std::numeric_limits::digits>, // User customised precision: precision_type >::type >::type type; #endif }; #endif namespace detail{ template inline int digits_imp(mpl::true_ const&) { #ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS BOOST_STATIC_ASSERT( ::std::numeric_limits::is_specialized); #else BOOST_ASSERT(::std::numeric_limits::is_specialized); #endif typedef typename boost::math::policies::precision::type p_t; return p_t::value; } template inline int digits_imp(mpl::false_ const&) { return tools::digits(); } } // namespace detail template inline int digits(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(T)) { typedef mpl::bool_< std::numeric_limits::is_specialized > tag_type; return detail::digits_imp(tag_type()); } template inline unsigned long get_max_series_iterations() { typedef typename Policy::max_series_iterations_type iter_type; return iter_type::value; } template inline unsigned long get_max_root_iterations() { typedef typename Policy::max_root_iterations_type iter_type; return iter_type::value; } namespace detail{ template struct series_factor_calc { static T get() { return ldexp(T(1.0), 1 - Digits::value); } }; template struct series_factor_calc { static T get() { return boost::math::tools::epsilon(); } }; template struct series_factor_calc { static T get() { static const boost::uintmax_t v = static_cast(1u) << (Digits::value - 1); return 1 / static_cast(v); } }; template struct series_factor_calc { static T get() { return boost::math::tools::epsilon(); } }; template inline T get_epsilon_imp(mpl::true_ const&) { #ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS BOOST_STATIC_ASSERT( ::std::numeric_limits::is_specialized); BOOST_STATIC_ASSERT( ::std::numeric_limits::radix == 2); #else BOOST_ASSERT(::std::numeric_limits::is_specialized); BOOST_ASSERT(::std::numeric_limits::radix == 2); #endif typedef typename boost::math::policies::precision::type p_t; typedef mpl::bool_::digits> is_small_int; typedef mpl::bool_= std::numeric_limits::digits> is_default_value; return series_factor_calc::get(); } template inline T get_epsilon_imp(mpl::false_ const&) { return tools::epsilon(); } } // namespace detail template inline T get_epsilon(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(T)) { typedef mpl::bool_< (std::numeric_limits::is_specialized && (std::numeric_limits::radix == 2)) > tag_type; return detail::get_epsilon_imp(tag_type()); } namespace detail{ template char test_is_policy(const policy*); double test_is_policy(...); template struct is_policy_imp { BOOST_STATIC_CONSTANT(bool, value = (sizeof(::boost::math::policies::detail::test_is_policy(static_cast(0))) == 1)); }; } template struct is_policy : public mpl::bool_< ::boost::math::policies::detail::is_policy_imp

::value> {}; // // Helper traits class for distribution error handling: // template struct constructor_error_check { typedef typename Policy::domain_error_type domain_error_type; typedef typename mpl::if_c< (domain_error_type::value == throw_on_error) || (domain_error_type::value == user_error), mpl::true_, mpl::false_>::type type; }; template struct method_error_check { typedef typename Policy::domain_error_type domain_error_type; typedef typename mpl::if_c< (domain_error_type::value == throw_on_error) && (domain_error_type::value != user_error), mpl::false_, mpl::true_>::type type; }; }}} // namespaces #endif // BOOST_MATH_POLICY_HPP