summaryrefslogtreecommitdiff
path: root/boost/math/policies/policy.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/math/policies/policy.hpp')
-rw-r--r--boost/math/policies/policy.hpp108
1 files changed, 77 insertions, 31 deletions
diff --git a/boost/math/policies/policy.hpp b/boost/math/policies/policy.hpp
index 71309fa116..de813fb8aa 100644
--- a/boost/math/policies/policy.hpp
+++ b/boost/math/policies/policy.hpp
@@ -33,9 +33,9 @@ namespace boost{ namespace math{
namespace tools{
template <class T>
-int digits(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(T));
+BOOST_MATH_CONSTEXPR int digits(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(T)) BOOST_NOEXCEPT;
template <class T>
-T epsilon(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(T));
+BOOST_MATH_CONSTEXPR T epsilon(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(T)) BOOST_MATH_NOEXCEPT(T);
}
@@ -44,6 +44,28 @@ namespace policies{
//
// Define macros for our default policies, if they're not defined already:
//
+// Special cases for exceptions disabled first:
+//
+#ifdef BOOST_NO_EXCEPTIONS
+# ifndef BOOST_MATH_DOMAIN_ERROR_POLICY
+# define BOOST_MATH_DOMAIN_ERROR_POLICY errno_on_error
+# endif
+# ifndef BOOST_MATH_POLE_ERROR_POLICY
+# define BOOST_MATH_POLE_ERROR_POLICY errno_on_error
+# endif
+# ifndef BOOST_MATH_OVERFLOW_ERROR_POLICY
+# define BOOST_MATH_OVERFLOW_ERROR_POLICY errno_on_error
+# endif
+# ifndef BOOST_MATH_EVALUATION_ERROR_POLICY
+# define BOOST_MATH_EVALUATION_ERROR_POLICY errno_on_error
+# endif
+# ifndef BOOST_MATH_ROUNDING_ERROR_POLICY
+# define BOOST_MATH_ROUNDING_ERROR_POLICY errno_on_error
+# endif
+#endif
+//
+// Then the regular cases:
+//
#ifndef BOOST_MATH_DOMAIN_ERROR_POLICY
#define BOOST_MATH_DOMAIN_ERROR_POLICY throw_on_error
#endif
@@ -622,81 +644,81 @@ struct normalise<policy<detail::forwarding_arg1, detail::forwarding_arg2>,
typedef policy<detail::forwarding_arg1, detail::forwarding_arg2> type;
};
-inline policy<> make_policy()
+inline BOOST_MATH_CONSTEXPR policy<> make_policy() BOOST_NOEXCEPT
{ return policy<>(); }
template <class A1>
-inline typename normalise<policy<>, A1>::type make_policy(const A1&)
+inline BOOST_MATH_CONSTEXPR typename normalise<policy<>, A1>::type make_policy(const A1&) BOOST_NOEXCEPT
{
typedef typename normalise<policy<>, A1>::type result_type;
return result_type();
}
template <class A1, class A2>
-inline typename normalise<policy<>, A1, A2>::type make_policy(const A1&, const A2&)
+inline BOOST_MATH_CONSTEXPR typename normalise<policy<>, A1, A2>::type make_policy(const A1&, const A2&) BOOST_NOEXCEPT
{
typedef typename normalise<policy<>, A1, A2>::type result_type;
return result_type();
}
template <class A1, class A2, class A3>
-inline typename normalise<policy<>, A1, A2, A3>::type make_policy(const A1&, const A2&, const A3&)
+inline BOOST_MATH_CONSTEXPR typename normalise<policy<>, A1, A2, A3>::type make_policy(const A1&, const A2&, const A3&) BOOST_NOEXCEPT
{
typedef typename normalise<policy<>, A1, A2, A3>::type result_type;
return result_type();
}
template <class A1, class A2, class A3, class A4>
-inline typename normalise<policy<>, A1, A2, A3, A4>::type make_policy(const A1&, const A2&, const A3&, const A4&)
+inline BOOST_MATH_CONSTEXPR typename normalise<policy<>, A1, A2, A3, A4>::type make_policy(const A1&, const A2&, const A3&, const A4&) BOOST_NOEXCEPT
{
typedef typename normalise<policy<>, A1, A2, A3, A4>::type result_type;
return result_type();
}
template <class A1, class A2, class A3, class A4, class A5>
-inline typename normalise<policy<>, A1, A2, A3, A4, A5>::type make_policy(const A1&, const A2&, const A3&, const A4&, const A5&)
+inline BOOST_MATH_CONSTEXPR typename normalise<policy<>, A1, A2, A3, A4, A5>::type make_policy(const A1&, const A2&, const A3&, const A4&, const A5&) BOOST_NOEXCEPT
{
typedef typename normalise<policy<>, A1, A2, A3, A4, A5>::type result_type;
return result_type();
}
template <class A1, class A2, class A3, class A4, class A5, class A6>
-inline typename normalise<policy<>, A1, A2, A3, A4, A5, A6>::type make_policy(const A1&, const A2&, const A3&, const A4&, const A5&, const A6&)
+inline BOOST_MATH_CONSTEXPR typename normalise<policy<>, A1, A2, A3, A4, A5, A6>::type make_policy(const A1&, const A2&, const A3&, const A4&, const A5&, const A6&) BOOST_NOEXCEPT
{
typedef typename normalise<policy<>, A1, A2, A3, A4, A5, A6>::type result_type;
return result_type();
}
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7>
-inline typename normalise<policy<>, A1, A2, A3, A4, A5, A6, A7>::type make_policy(const A1&, const A2&, const A3&, const A4&, const A5&, const A6&, const A7&)
+inline BOOST_MATH_CONSTEXPR typename normalise<policy<>, A1, A2, A3, A4, A5, A6, A7>::type make_policy(const A1&, const A2&, const A3&, const A4&, const A5&, const A6&, const A7&) BOOST_NOEXCEPT
{
typedef typename normalise<policy<>, A1, A2, A3, A4, A5, A6, A7>::type result_type;
return result_type();
}
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
-inline typename normalise<policy<>, 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&)
+inline BOOST_MATH_CONSTEXPR typename normalise<policy<>, 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&) BOOST_NOEXCEPT
{
typedef typename normalise<policy<>, A1, A2, A3, A4, A5, A6, A7, A8>::type result_type;
return result_type();
}
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
-inline typename normalise<policy<>, 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&)
+inline BOOST_MATH_CONSTEXPR typename normalise<policy<>, 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&) BOOST_NOEXCEPT
{
typedef typename normalise<policy<>, A1, A2, A3, A4, A5, A6, A7, A8, A9>::type result_type;
return result_type();
}
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10>
-inline typename normalise<policy<>, 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&)
+inline BOOST_MATH_CONSTEXPR typename normalise<policy<>, 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&) BOOST_NOEXCEPT
{
typedef typename normalise<policy<>, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10>::type result_type;
return result_type();
}
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11>
-inline typename normalise<policy<>, 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&)
+inline BOOST_MATH_CONSTEXPR typename normalise<policy<>, 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&) BOOST_NOEXCEPT
{
typedef typename normalise<policy<>, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11>::type result_type;
return result_type();
@@ -825,7 +847,7 @@ struct precision<BOOST_MATH_FLOAT128_TYPE, Policy>
namespace detail{
template <class T, class Policy>
-inline int digits_imp(mpl::true_ const&)
+inline BOOST_MATH_CONSTEXPR int digits_imp(mpl::true_ const&) BOOST_NOEXCEPT
{
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
BOOST_STATIC_ASSERT( ::std::numeric_limits<T>::is_specialized);
@@ -837,7 +859,7 @@ inline int digits_imp(mpl::true_ const&)
}
template <class T, class Policy>
-inline int digits_imp(mpl::false_ const&)
+inline BOOST_MATH_CONSTEXPR int digits_imp(mpl::false_ const&) BOOST_NOEXCEPT
{
return tools::digits<T>();
}
@@ -845,26 +867,26 @@ inline int digits_imp(mpl::false_ const&)
} // namespace detail
template <class T, class Policy>
-inline int digits(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(T))
+inline BOOST_MATH_CONSTEXPR int digits(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(T)) BOOST_NOEXCEPT
{
typedef mpl::bool_< std::numeric_limits<T>::is_specialized > tag_type;
return detail::digits_imp<T, Policy>(tag_type());
}
template <class T, class Policy>
-inline int digits_base10(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(T))
+inline BOOST_MATH_CONSTEXPR int digits_base10(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(T)) BOOST_NOEXCEPT
{
return boost::math::policies::digits<T, Policy>() * 301 / 1000L;
}
template <class Policy>
-inline unsigned long get_max_series_iterations()
+inline BOOST_MATH_CONSTEXPR unsigned long get_max_series_iterations() BOOST_NOEXCEPT
{
typedef typename Policy::max_series_iterations_type iter_type;
return iter_type::value;
}
template <class Policy>
-inline unsigned long get_max_root_iterations()
+inline BOOST_MATH_CONSTEXPR unsigned long get_max_root_iterations() BOOST_NOEXCEPT
{
typedef typename Policy::max_root_iterations_type iter_type;
return iter_type::value;
@@ -875,7 +897,7 @@ namespace detail{
template <class T, class Digits, class Small, class Default>
struct series_factor_calc
{
- static T get()
+ static T get() BOOST_MATH_NOEXCEPT(T)
{
return ldexp(T(1.0), 1 - Digits::value);
}
@@ -884,7 +906,7 @@ struct series_factor_calc
template <class T, class Digits>
struct series_factor_calc<T, Digits, mpl::true_, mpl::true_>
{
- static T get()
+ static BOOST_MATH_CONSTEXPR T get() BOOST_MATH_NOEXCEPT(T)
{
return boost::math::tools::epsilon<T>();
}
@@ -892,23 +914,24 @@ struct series_factor_calc<T, Digits, mpl::true_, mpl::true_>
template <class T, class Digits>
struct series_factor_calc<T, Digits, mpl::true_, mpl::false_>
{
- static T get()
+ BOOST_STATIC_CONSTANT(boost::uintmax_t, v = static_cast<boost::uintmax_t>(1u) << (Digits::value - 1));
+
+ static BOOST_MATH_CONSTEXPR T get() BOOST_MATH_NOEXCEPT(T)
{
- static const boost::uintmax_t v = static_cast<boost::uintmax_t>(1u) << (Digits::value - 1);
return 1 / static_cast<T>(v);
}
};
template <class T, class Digits>
struct series_factor_calc<T, Digits, mpl::false_, mpl::true_>
{
- static T get()
+ static BOOST_MATH_CONSTEXPR T get() BOOST_MATH_NOEXCEPT(T)
{
return boost::math::tools::epsilon<T>();
}
};
template <class T, class Policy>
-inline T get_epsilon_imp(mpl::true_ const&)
+inline BOOST_MATH_CONSTEXPR T get_epsilon_imp(mpl::true_ const&) BOOST_MATH_NOEXCEPT(T)
{
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
BOOST_STATIC_ASSERT( ::std::numeric_limits<T>::is_specialized);
@@ -924,7 +947,7 @@ inline T get_epsilon_imp(mpl::true_ const&)
}
template <class T, class Policy>
-inline T get_epsilon_imp(mpl::false_ const&)
+inline BOOST_MATH_CONSTEXPR T get_epsilon_imp(mpl::false_ const&) BOOST_MATH_NOEXCEPT(T)
{
return tools::epsilon<T>();
}
@@ -932,7 +955,7 @@ inline T get_epsilon_imp(mpl::false_ const&)
} // namespace detail
template <class T, class Policy>
-inline T get_epsilon(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(T))
+inline BOOST_MATH_CONSTEXPR T get_epsilon(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(T)) BOOST_MATH_NOEXCEPT(T)
{
typedef mpl::bool_< (std::numeric_limits<T>::is_specialized && (std::numeric_limits<T>::radix == 2)) > tag_type;
return detail::get_epsilon_imp<T, Policy>(tag_type());
@@ -973,7 +996,7 @@ 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),
+ (domain_error_type::value == throw_on_error) || (domain_error_type::value == user_error) || (domain_error_type::value == errno_on_error),
mpl::true_,
mpl::false_>::type type;
};
@@ -987,10 +1010,33 @@ struct method_error_check
mpl::false_,
mpl::true_>::type type;
};
+//
+// Does the Policy ever throw on error?
+//
+template <class Policy>
+struct is_noexcept_error_policy
+{
+ typedef typename Policy::domain_error_type t1;
+ typedef typename Policy::pole_error_type t2;
+ typedef typename Policy::overflow_error_type t3;
+ typedef typename Policy::underflow_error_type t4;
+ typedef typename Policy::denorm_error_type t5;
+ typedef typename Policy::evaluation_error_type t6;
+ typedef typename Policy::rounding_error_type t7;
+ typedef typename Policy::indeterminate_result_error_type t8;
+
+ BOOST_STATIC_CONSTANT(bool, value =
+ ((t1::value != throw_on_error) && (t1::value != user_error)
+ && (t2::value != throw_on_error) && (t2::value != user_error)
+ && (t3::value != throw_on_error) && (t3::value != user_error)
+ && (t4::value != throw_on_error) && (t4::value != user_error)
+ && (t5::value != throw_on_error) && (t5::value != user_error)
+ && (t6::value != throw_on_error) && (t6::value != user_error)
+ && (t7::value != throw_on_error) && (t7::value != user_error)
+ && (t8::value != throw_on_error) && (t8::value != user_error)));
+};
}}} // namespaces
#endif // BOOST_MATH_POLICY_HPP
-
-