policy.hpp 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040
  1. // Copyright John Maddock 2007.
  2. // Use, modification and distribution are subject to the
  3. // Boost Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef BOOST_MATH_POLICY_HPP
  6. #define BOOST_MATH_POLICY_HPP
  7. #include <boost/mpl/list.hpp>
  8. #include <boost/mpl/contains.hpp>
  9. #include <boost/mpl/if.hpp>
  10. #include <boost/mpl/find_if.hpp>
  11. #include <boost/mpl/remove_if.hpp>
  12. #include <boost/mpl/vector.hpp>
  13. #include <boost/mpl/push_back.hpp>
  14. #include <boost/mpl/at.hpp>
  15. #include <boost/mpl/size.hpp>
  16. #include <boost/mpl/comparison.hpp>
  17. #include <boost/type_traits/is_same.hpp>
  18. #include <boost/static_assert.hpp>
  19. #include <boost/assert.hpp>
  20. #include <boost/math/tools/config.hpp>
  21. #include <limits>
  22. // Sadly we do need the .h versions of these to be sure of getting
  23. // FLT_MANT_DIG etc.
  24. #include <limits.h>
  25. #include <stdlib.h>
  26. #include <stddef.h>
  27. #include <math.h>
  28. namespace boost{ namespace math{
  29. namespace tools{
  30. template <class T>
  31. BOOST_MATH_CONSTEXPR int digits(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(T)) BOOST_NOEXCEPT;
  32. template <class T>
  33. BOOST_MATH_CONSTEXPR T epsilon(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(T)) BOOST_MATH_NOEXCEPT(T);
  34. }
  35. namespace policies{
  36. //
  37. // Define macros for our default policies, if they're not defined already:
  38. //
  39. // Special cases for exceptions disabled first:
  40. //
  41. #ifdef BOOST_NO_EXCEPTIONS
  42. # ifndef BOOST_MATH_DOMAIN_ERROR_POLICY
  43. # define BOOST_MATH_DOMAIN_ERROR_POLICY errno_on_error
  44. # endif
  45. # ifndef BOOST_MATH_POLE_ERROR_POLICY
  46. # define BOOST_MATH_POLE_ERROR_POLICY errno_on_error
  47. # endif
  48. # ifndef BOOST_MATH_OVERFLOW_ERROR_POLICY
  49. # define BOOST_MATH_OVERFLOW_ERROR_POLICY errno_on_error
  50. # endif
  51. # ifndef BOOST_MATH_EVALUATION_ERROR_POLICY
  52. # define BOOST_MATH_EVALUATION_ERROR_POLICY errno_on_error
  53. # endif
  54. # ifndef BOOST_MATH_ROUNDING_ERROR_POLICY
  55. # define BOOST_MATH_ROUNDING_ERROR_POLICY errno_on_error
  56. # endif
  57. #endif
  58. //
  59. // Then the regular cases:
  60. //
  61. #ifndef BOOST_MATH_DOMAIN_ERROR_POLICY
  62. #define BOOST_MATH_DOMAIN_ERROR_POLICY throw_on_error
  63. #endif
  64. #ifndef BOOST_MATH_POLE_ERROR_POLICY
  65. #define BOOST_MATH_POLE_ERROR_POLICY throw_on_error
  66. #endif
  67. #ifndef BOOST_MATH_OVERFLOW_ERROR_POLICY
  68. #define BOOST_MATH_OVERFLOW_ERROR_POLICY throw_on_error
  69. #endif
  70. #ifndef BOOST_MATH_EVALUATION_ERROR_POLICY
  71. #define BOOST_MATH_EVALUATION_ERROR_POLICY throw_on_error
  72. #endif
  73. #ifndef BOOST_MATH_ROUNDING_ERROR_POLICY
  74. #define BOOST_MATH_ROUNDING_ERROR_POLICY throw_on_error
  75. #endif
  76. #ifndef BOOST_MATH_UNDERFLOW_ERROR_POLICY
  77. #define BOOST_MATH_UNDERFLOW_ERROR_POLICY ignore_error
  78. #endif
  79. #ifndef BOOST_MATH_DENORM_ERROR_POLICY
  80. #define BOOST_MATH_DENORM_ERROR_POLICY ignore_error
  81. #endif
  82. #ifndef BOOST_MATH_INDETERMINATE_RESULT_ERROR_POLICY
  83. #define BOOST_MATH_INDETERMINATE_RESULT_ERROR_POLICY ignore_error
  84. #endif
  85. #ifndef BOOST_MATH_DIGITS10_POLICY
  86. #define BOOST_MATH_DIGITS10_POLICY 0
  87. #endif
  88. #ifndef BOOST_MATH_PROMOTE_FLOAT_POLICY
  89. #define BOOST_MATH_PROMOTE_FLOAT_POLICY true
  90. #endif
  91. #ifndef BOOST_MATH_PROMOTE_DOUBLE_POLICY
  92. #ifdef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  93. #define BOOST_MATH_PROMOTE_DOUBLE_POLICY false
  94. #else
  95. #define BOOST_MATH_PROMOTE_DOUBLE_POLICY true
  96. #endif
  97. #endif
  98. #ifndef BOOST_MATH_DISCRETE_QUANTILE_POLICY
  99. #define BOOST_MATH_DISCRETE_QUANTILE_POLICY integer_round_outwards
  100. #endif
  101. #ifndef BOOST_MATH_ASSERT_UNDEFINED_POLICY
  102. #define BOOST_MATH_ASSERT_UNDEFINED_POLICY true
  103. #endif
  104. #ifndef BOOST_MATH_MAX_SERIES_ITERATION_POLICY
  105. #define BOOST_MATH_MAX_SERIES_ITERATION_POLICY 1000000
  106. #endif
  107. #ifndef BOOST_MATH_MAX_ROOT_ITERATION_POLICY
  108. #define BOOST_MATH_MAX_ROOT_ITERATION_POLICY 200
  109. #endif
  110. #if !defined(__BORLANDC__)
  111. #define BOOST_MATH_META_INT(type, name, Default)\
  112. template <type N = Default> struct name : public boost::mpl::int_<N>{};\
  113. namespace detail{\
  114. template <type N>\
  115. char test_is_valid_arg(const name<N>*);\
  116. char test_is_default_arg(const name<Default>*);\
  117. template <class T> struct is_##name##_imp\
  118. {\
  119. template <type N> static char test(const name<N>*);\
  120. static double test(...);\
  121. BOOST_STATIC_CONSTANT(bool, value = sizeof(test(static_cast<T*>(0))) == 1);\
  122. };\
  123. }\
  124. template <class T> struct is_##name : public boost::mpl::bool_< ::boost::math::policies::detail::is_##name##_imp<T>::value>{};
  125. #define BOOST_MATH_META_BOOL(name, Default)\
  126. template <bool N = Default> struct name : public boost::mpl::bool_<N>{};\
  127. namespace detail{\
  128. template <bool N>\
  129. char test_is_valid_arg(const name<N>*);\
  130. char test_is_default_arg(const name<Default>*);\
  131. template <class T> struct is_##name##_imp\
  132. {\
  133. template <bool N> static char test(const name<N>*);\
  134. static double test(...);\
  135. BOOST_STATIC_CONSTANT(bool, value = sizeof(test(static_cast<T*>(0))) == 1);\
  136. };\
  137. }\
  138. template <class T> struct is_##name : public boost::mpl::bool_< ::boost::math::policies::detail::is_##name##_imp<T>::value>{};
  139. #else
  140. #define BOOST_MATH_META_INT(Type, name, Default)\
  141. template <Type N = Default> struct name : public boost::mpl::int_<N>{};\
  142. namespace detail{\
  143. template <Type N>\
  144. char test_is_valid_arg(const name<N>*);\
  145. char test_is_default_arg(const name<Default>*);\
  146. template <class T> struct is_##name##_tester\
  147. {\
  148. template <Type N> static char test(const name<N>&);\
  149. static double test(...);\
  150. };\
  151. template <class T> struct is_##name##_imp\
  152. {\
  153. static T inst;\
  154. BOOST_STATIC_CONSTANT(bool, value = sizeof( ::boost::math::policies::detail::is_##name##_tester<T>::test(inst)) == 1);\
  155. };\
  156. }\
  157. template <class T> struct is_##name : public boost::mpl::bool_< ::boost::math::policies::detail::is_##name##_imp<T>::value>\
  158. {\
  159. template <class U> struct apply{ typedef is_##name<U> type; };\
  160. };
  161. #define BOOST_MATH_META_BOOL(name, Default)\
  162. template <bool N = Default> struct name : public boost::mpl::bool_<N>{};\
  163. namespace detail{\
  164. template <bool N>\
  165. char test_is_valid_arg(const name<N>*);\
  166. char test_is_default_arg(const name<Default>*);\
  167. template <class T> struct is_##name##_tester\
  168. {\
  169. template <bool N> static char test(const name<N>&);\
  170. static double test(...);\
  171. };\
  172. template <class T> struct is_##name##_imp\
  173. {\
  174. static T inst;\
  175. BOOST_STATIC_CONSTANT(bool, value = sizeof( ::boost::math::policies::detail::is_##name##_tester<T>::test(inst)) == 1);\
  176. };\
  177. }\
  178. template <class T> struct is_##name : public boost::mpl::bool_< ::boost::math::policies::detail::is_##name##_imp<T>::value>\
  179. {\
  180. template <class U> struct apply{ typedef is_##name<U> type; };\
  181. };
  182. #endif
  183. //
  184. // Begin by defining policy types for error handling:
  185. //
  186. enum error_policy_type
  187. {
  188. throw_on_error = 0,
  189. errno_on_error = 1,
  190. ignore_error = 2,
  191. user_error = 3
  192. };
  193. BOOST_MATH_META_INT(error_policy_type, domain_error, BOOST_MATH_DOMAIN_ERROR_POLICY)
  194. BOOST_MATH_META_INT(error_policy_type, pole_error, BOOST_MATH_POLE_ERROR_POLICY)
  195. BOOST_MATH_META_INT(error_policy_type, overflow_error, BOOST_MATH_OVERFLOW_ERROR_POLICY)
  196. BOOST_MATH_META_INT(error_policy_type, underflow_error, BOOST_MATH_UNDERFLOW_ERROR_POLICY)
  197. BOOST_MATH_META_INT(error_policy_type, denorm_error, BOOST_MATH_DENORM_ERROR_POLICY)
  198. BOOST_MATH_META_INT(error_policy_type, evaluation_error, BOOST_MATH_EVALUATION_ERROR_POLICY)
  199. BOOST_MATH_META_INT(error_policy_type, rounding_error, BOOST_MATH_ROUNDING_ERROR_POLICY)
  200. BOOST_MATH_META_INT(error_policy_type, indeterminate_result_error, BOOST_MATH_INDETERMINATE_RESULT_ERROR_POLICY)
  201. //
  202. // Policy types for internal promotion:
  203. //
  204. BOOST_MATH_META_BOOL(promote_float, BOOST_MATH_PROMOTE_FLOAT_POLICY)
  205. BOOST_MATH_META_BOOL(promote_double, BOOST_MATH_PROMOTE_DOUBLE_POLICY)
  206. BOOST_MATH_META_BOOL(assert_undefined, BOOST_MATH_ASSERT_UNDEFINED_POLICY)
  207. //
  208. // Policy types for discrete quantiles:
  209. //
  210. enum discrete_quantile_policy_type
  211. {
  212. real,
  213. integer_round_outwards,
  214. integer_round_inwards,
  215. integer_round_down,
  216. integer_round_up,
  217. integer_round_nearest
  218. };
  219. BOOST_MATH_META_INT(discrete_quantile_policy_type, discrete_quantile, BOOST_MATH_DISCRETE_QUANTILE_POLICY)
  220. //
  221. // Precision:
  222. //
  223. BOOST_MATH_META_INT(int, digits10, BOOST_MATH_DIGITS10_POLICY)
  224. BOOST_MATH_META_INT(int, digits2, 0)
  225. //
  226. // Iterations:
  227. //
  228. BOOST_MATH_META_INT(unsigned long, max_series_iterations, BOOST_MATH_MAX_SERIES_ITERATION_POLICY)
  229. BOOST_MATH_META_INT(unsigned long, max_root_iterations, BOOST_MATH_MAX_ROOT_ITERATION_POLICY)
  230. //
  231. // Define the names for each possible policy:
  232. //
  233. #define BOOST_MATH_PARAMETER(name)\
  234. BOOST_PARAMETER_TEMPLATE_KEYWORD(name##_name)\
  235. BOOST_PARAMETER_NAME(name##_name)
  236. struct default_policy{};
  237. namespace detail{
  238. //
  239. // Trait to work out bits precision from digits10 and digits2:
  240. //
  241. template <class Digits10, class Digits2>
  242. struct precision
  243. {
  244. //
  245. // Now work out the precision:
  246. //
  247. typedef typename mpl::if_c<
  248. (Digits10::value == 0),
  249. digits2<0>,
  250. digits2<((Digits10::value + 1) * 1000L) / 301L>
  251. >::type digits2_type;
  252. public:
  253. #ifdef __BORLANDC__
  254. typedef typename mpl::if_c<
  255. (Digits2::value > ::boost::math::policies::detail::precision<Digits10,Digits2>::digits2_type::value),
  256. Digits2, digits2_type>::type type;
  257. #else
  258. typedef typename mpl::if_c<
  259. (Digits2::value > digits2_type::value),
  260. Digits2, digits2_type>::type type;
  261. #endif
  262. };
  263. template <class A, class B, bool b>
  264. struct select_result
  265. {
  266. typedef A type;
  267. };
  268. template <class A, class B>
  269. struct select_result<A, B, false>
  270. {
  271. typedef typename mpl::deref<B>::type type;
  272. };
  273. template <class Seq, class Pred, class DefaultType>
  274. struct find_arg
  275. {
  276. private:
  277. typedef typename mpl::find_if<Seq, Pred>::type iter;
  278. typedef typename mpl::end<Seq>::type end_type;
  279. public:
  280. typedef typename select_result<
  281. DefaultType, iter,
  282. ::boost::is_same<iter, end_type>::value>::type type;
  283. };
  284. double test_is_valid_arg(...);
  285. double test_is_default_arg(...);
  286. char test_is_valid_arg(const default_policy*);
  287. char test_is_default_arg(const default_policy*);
  288. template <class T>
  289. struct is_valid_policy_imp
  290. {
  291. BOOST_STATIC_CONSTANT(bool, value = sizeof(::boost::math::policies::detail::test_is_valid_arg(static_cast<T*>(0))) == 1);
  292. };
  293. template <class T>
  294. struct is_default_policy_imp
  295. {
  296. BOOST_STATIC_CONSTANT(bool, value = sizeof(::boost::math::policies::detail::test_is_default_arg(static_cast<T*>(0))) == 1);
  297. };
  298. template <class T> struct is_valid_policy
  299. : public mpl::bool_<
  300. ::boost::math::policies::detail::is_valid_policy_imp<T>::value>
  301. {};
  302. template <class T> struct is_default_policy
  303. : public mpl::bool_<
  304. ::boost::math::policies::detail::is_default_policy_imp<T>::value>
  305. {
  306. template <class U>
  307. struct apply
  308. {
  309. typedef is_default_policy<U> type;
  310. };
  311. };
  312. template <class Seq, class T, int N>
  313. struct append_N
  314. {
  315. typedef typename mpl::push_back<Seq, T>::type new_seq;
  316. typedef typename append_N<new_seq, T, N-1>::type type;
  317. };
  318. template <class Seq, class T>
  319. struct append_N<Seq, T, 0>
  320. {
  321. typedef Seq type;
  322. };
  323. //
  324. // Traits class to work out what template parameters our default
  325. // policy<> class will have when modified for forwarding:
  326. //
  327. template <bool f, bool d>
  328. struct default_args
  329. {
  330. typedef promote_float<false> arg1;
  331. typedef promote_double<false> arg2;
  332. };
  333. template <>
  334. struct default_args<false, false>
  335. {
  336. typedef default_policy arg1;
  337. typedef default_policy arg2;
  338. };
  339. template <>
  340. struct default_args<true, false>
  341. {
  342. typedef promote_float<false> arg1;
  343. typedef default_policy arg2;
  344. };
  345. template <>
  346. struct default_args<false, true>
  347. {
  348. typedef promote_double<false> arg1;
  349. typedef default_policy arg2;
  350. };
  351. typedef default_args<BOOST_MATH_PROMOTE_FLOAT_POLICY, BOOST_MATH_PROMOTE_DOUBLE_POLICY>::arg1 forwarding_arg1;
  352. typedef default_args<BOOST_MATH_PROMOTE_FLOAT_POLICY, BOOST_MATH_PROMOTE_DOUBLE_POLICY>::arg2 forwarding_arg2;
  353. } // detail
  354. //
  355. // Now define the policy type with enough arguments to handle all
  356. // the policies:
  357. //
  358. template <class A1 = default_policy,
  359. class A2 = default_policy,
  360. class A3 = default_policy,
  361. class A4 = default_policy,
  362. class A5 = default_policy,
  363. class A6 = default_policy,
  364. class A7 = default_policy,
  365. class A8 = default_policy,
  366. class A9 = default_policy,
  367. class A10 = default_policy,
  368. class A11 = default_policy,
  369. class A12 = default_policy,
  370. class A13 = default_policy>
  371. struct policy
  372. {
  373. private:
  374. //
  375. // Validate all our arguments:
  376. //
  377. BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy<A1>::value);
  378. BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy<A2>::value);
  379. BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy<A3>::value);
  380. BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy<A4>::value);
  381. BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy<A5>::value);
  382. BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy<A6>::value);
  383. BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy<A7>::value);
  384. BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy<A8>::value);
  385. BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy<A9>::value);
  386. BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy<A10>::value);
  387. BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy<A11>::value);
  388. BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy<A12>::value);
  389. BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy<A13>::value);
  390. //
  391. // Typelist of the arguments:
  392. //
  393. typedef mpl::list<A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13> arg_list;
  394. public:
  395. typedef typename detail::find_arg<arg_list, is_domain_error<mpl::_1>, domain_error<> >::type domain_error_type;
  396. typedef typename detail::find_arg<arg_list, is_pole_error<mpl::_1>, pole_error<> >::type pole_error_type;
  397. typedef typename detail::find_arg<arg_list, is_overflow_error<mpl::_1>, overflow_error<> >::type overflow_error_type;
  398. typedef typename detail::find_arg<arg_list, is_underflow_error<mpl::_1>, underflow_error<> >::type underflow_error_type;
  399. typedef typename detail::find_arg<arg_list, is_denorm_error<mpl::_1>, denorm_error<> >::type denorm_error_type;
  400. typedef typename detail::find_arg<arg_list, is_evaluation_error<mpl::_1>, evaluation_error<> >::type evaluation_error_type;
  401. typedef typename detail::find_arg<arg_list, is_rounding_error<mpl::_1>, rounding_error<> >::type rounding_error_type;
  402. typedef typename detail::find_arg<arg_list, is_indeterminate_result_error<mpl::_1>, indeterminate_result_error<> >::type indeterminate_result_error_type;
  403. private:
  404. //
  405. // Now work out the precision:
  406. //
  407. typedef typename detail::find_arg<arg_list, is_digits10<mpl::_1>, digits10<> >::type digits10_type;
  408. typedef typename detail::find_arg<arg_list, is_digits2<mpl::_1>, digits2<> >::type bits_precision_type;
  409. public:
  410. typedef typename detail::precision<digits10_type, bits_precision_type>::type precision_type;
  411. //
  412. // Internal promotion:
  413. //
  414. typedef typename detail::find_arg<arg_list, is_promote_float<mpl::_1>, promote_float<> >::type promote_float_type;
  415. typedef typename detail::find_arg<arg_list, is_promote_double<mpl::_1>, promote_double<> >::type promote_double_type;
  416. //
  417. // Discrete quantiles:
  418. //
  419. typedef typename detail::find_arg<arg_list, is_discrete_quantile<mpl::_1>, discrete_quantile<> >::type discrete_quantile_type;
  420. //
  421. // Mathematically undefined properties:
  422. //
  423. typedef typename detail::find_arg<arg_list, is_assert_undefined<mpl::_1>, assert_undefined<> >::type assert_undefined_type;
  424. //
  425. // Max iterations:
  426. //
  427. typedef typename detail::find_arg<arg_list, is_max_series_iterations<mpl::_1>, max_series_iterations<> >::type max_series_iterations_type;
  428. typedef typename detail::find_arg<arg_list, is_max_root_iterations<mpl::_1>, max_root_iterations<> >::type max_root_iterations_type;
  429. };
  430. //
  431. // These full specializations are defined to reduce the amount of
  432. // template instantiations that have to take place when using the default
  433. // policies, they have quite a large impact on compile times:
  434. //
  435. template <>
  436. struct policy<default_policy, default_policy, default_policy, default_policy, default_policy, default_policy, default_policy, default_policy, default_policy, default_policy, default_policy>
  437. {
  438. public:
  439. typedef domain_error<> domain_error_type;
  440. typedef pole_error<> pole_error_type;
  441. typedef overflow_error<> overflow_error_type;
  442. typedef underflow_error<> underflow_error_type;
  443. typedef denorm_error<> denorm_error_type;
  444. typedef evaluation_error<> evaluation_error_type;
  445. typedef rounding_error<> rounding_error_type;
  446. typedef indeterminate_result_error<> indeterminate_result_error_type;
  447. #if BOOST_MATH_DIGITS10_POLICY == 0
  448. typedef digits2<> precision_type;
  449. #else
  450. typedef detail::precision<digits10<>, digits2<> >::type precision_type;
  451. #endif
  452. typedef promote_float<> promote_float_type;
  453. typedef promote_double<> promote_double_type;
  454. typedef discrete_quantile<> discrete_quantile_type;
  455. typedef assert_undefined<> assert_undefined_type;
  456. typedef max_series_iterations<> max_series_iterations_type;
  457. typedef max_root_iterations<> max_root_iterations_type;
  458. };
  459. template <>
  460. struct policy<detail::forwarding_arg1, detail::forwarding_arg2, default_policy, default_policy, default_policy, default_policy, default_policy, default_policy, default_policy, default_policy, default_policy>
  461. {
  462. public:
  463. typedef domain_error<> domain_error_type;
  464. typedef pole_error<> pole_error_type;
  465. typedef overflow_error<> overflow_error_type;
  466. typedef underflow_error<> underflow_error_type;
  467. typedef denorm_error<> denorm_error_type;
  468. typedef evaluation_error<> evaluation_error_type;
  469. typedef rounding_error<> rounding_error_type;
  470. typedef indeterminate_result_error<> indeterminate_result_error_type;
  471. #if BOOST_MATH_DIGITS10_POLICY == 0
  472. typedef digits2<> precision_type;
  473. #else
  474. typedef detail::precision<digits10<>, digits2<> >::type precision_type;
  475. #endif
  476. typedef promote_float<false> promote_float_type;
  477. typedef promote_double<false> promote_double_type;
  478. typedef discrete_quantile<> discrete_quantile_type;
  479. typedef assert_undefined<> assert_undefined_type;
  480. typedef max_series_iterations<> max_series_iterations_type;
  481. typedef max_root_iterations<> max_root_iterations_type;
  482. };
  483. template <class Policy,
  484. class A1 = default_policy,
  485. class A2 = default_policy,
  486. class A3 = default_policy,
  487. class A4 = default_policy,
  488. class A5 = default_policy,
  489. class A6 = default_policy,
  490. class A7 = default_policy,
  491. class A8 = default_policy,
  492. class A9 = default_policy,
  493. class A10 = default_policy,
  494. class A11 = default_policy,
  495. class A12 = default_policy,
  496. class A13 = default_policy>
  497. struct normalise
  498. {
  499. private:
  500. typedef mpl::list<A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13> arg_list;
  501. typedef typename detail::find_arg<arg_list, is_domain_error<mpl::_1>, typename Policy::domain_error_type >::type domain_error_type;
  502. typedef typename detail::find_arg<arg_list, is_pole_error<mpl::_1>, typename Policy::pole_error_type >::type pole_error_type;
  503. typedef typename detail::find_arg<arg_list, is_overflow_error<mpl::_1>, typename Policy::overflow_error_type >::type overflow_error_type;
  504. typedef typename detail::find_arg<arg_list, is_underflow_error<mpl::_1>, typename Policy::underflow_error_type >::type underflow_error_type;
  505. typedef typename detail::find_arg<arg_list, is_denorm_error<mpl::_1>, typename Policy::denorm_error_type >::type denorm_error_type;
  506. typedef typename detail::find_arg<arg_list, is_evaluation_error<mpl::_1>, typename Policy::evaluation_error_type >::type evaluation_error_type;
  507. typedef typename detail::find_arg<arg_list, is_rounding_error<mpl::_1>, typename Policy::rounding_error_type >::type rounding_error_type;
  508. typedef typename detail::find_arg<arg_list, is_indeterminate_result_error<mpl::_1>, typename Policy::indeterminate_result_error_type >::type indeterminate_result_error_type;
  509. //
  510. // Now work out the precision:
  511. //
  512. typedef typename detail::find_arg<arg_list, is_digits10<mpl::_1>, digits10<> >::type digits10_type;
  513. typedef typename detail::find_arg<arg_list, is_digits2<mpl::_1>, typename Policy::precision_type >::type bits_precision_type;
  514. typedef typename detail::precision<digits10_type, bits_precision_type>::type precision_type;
  515. //
  516. // Internal promotion:
  517. //
  518. typedef typename detail::find_arg<arg_list, is_promote_float<mpl::_1>, typename Policy::promote_float_type >::type promote_float_type;
  519. typedef typename detail::find_arg<arg_list, is_promote_double<mpl::_1>, typename Policy::promote_double_type >::type promote_double_type;
  520. //
  521. // Discrete quantiles:
  522. //
  523. typedef typename detail::find_arg<arg_list, is_discrete_quantile<mpl::_1>, typename Policy::discrete_quantile_type >::type discrete_quantile_type;
  524. //
  525. // Mathematically undefined properties:
  526. //
  527. typedef typename detail::find_arg<arg_list, is_assert_undefined<mpl::_1>, typename Policy::assert_undefined_type >::type assert_undefined_type;
  528. //
  529. // Max iterations:
  530. //
  531. typedef typename detail::find_arg<arg_list, is_max_series_iterations<mpl::_1>, typename Policy::max_series_iterations_type>::type max_series_iterations_type;
  532. typedef typename detail::find_arg<arg_list, is_max_root_iterations<mpl::_1>, typename Policy::max_root_iterations_type>::type max_root_iterations_type;
  533. //
  534. // Define a typelist of the policies:
  535. //
  536. typedef mpl::vector<
  537. domain_error_type,
  538. pole_error_type,
  539. overflow_error_type,
  540. underflow_error_type,
  541. denorm_error_type,
  542. evaluation_error_type,
  543. rounding_error_type,
  544. indeterminate_result_error_type,
  545. precision_type,
  546. promote_float_type,
  547. promote_double_type,
  548. discrete_quantile_type,
  549. assert_undefined_type,
  550. max_series_iterations_type,
  551. max_root_iterations_type> result_list;
  552. //
  553. // Remove all the policies that are the same as the default:
  554. //
  555. typedef typename mpl::remove_if<result_list, detail::is_default_policy<mpl::_> >::type reduced_list;
  556. //
  557. // Pad out the list with defaults:
  558. //
  559. typedef typename detail::append_N<reduced_list, default_policy, (14 - ::boost::mpl::size<reduced_list>::value)>::type result_type;
  560. public:
  561. typedef policy<
  562. typename mpl::at<result_type, mpl::int_<0> >::type,
  563. typename mpl::at<result_type, mpl::int_<1> >::type,
  564. typename mpl::at<result_type, mpl::int_<2> >::type,
  565. typename mpl::at<result_type, mpl::int_<3> >::type,
  566. typename mpl::at<result_type, mpl::int_<4> >::type,
  567. typename mpl::at<result_type, mpl::int_<5> >::type,
  568. typename mpl::at<result_type, mpl::int_<6> >::type,
  569. typename mpl::at<result_type, mpl::int_<7> >::type,
  570. typename mpl::at<result_type, mpl::int_<8> >::type,
  571. typename mpl::at<result_type, mpl::int_<9> >::type,
  572. typename mpl::at<result_type, mpl::int_<10> >::type,
  573. typename mpl::at<result_type, mpl::int_<11> >::type,
  574. typename mpl::at<result_type, mpl::int_<12> >::type > type;
  575. };
  576. //
  577. // Full specialisation to speed up compilation of the common case:
  578. //
  579. template <>
  580. struct normalise<policy<>,
  581. promote_float<false>,
  582. promote_double<false>,
  583. discrete_quantile<>,
  584. assert_undefined<>,
  585. default_policy,
  586. default_policy,
  587. default_policy,
  588. default_policy,
  589. default_policy,
  590. default_policy,
  591. default_policy>
  592. {
  593. typedef policy<detail::forwarding_arg1, detail::forwarding_arg2> type;
  594. };
  595. template <>
  596. struct normalise<policy<detail::forwarding_arg1, detail::forwarding_arg2>,
  597. promote_float<false>,
  598. promote_double<false>,
  599. discrete_quantile<>,
  600. assert_undefined<>,
  601. default_policy,
  602. default_policy,
  603. default_policy,
  604. default_policy,
  605. default_policy,
  606. default_policy,
  607. default_policy>
  608. {
  609. typedef policy<detail::forwarding_arg1, detail::forwarding_arg2> type;
  610. };
  611. inline BOOST_MATH_CONSTEXPR policy<> make_policy() BOOST_NOEXCEPT
  612. { return policy<>(); }
  613. template <class A1>
  614. inline BOOST_MATH_CONSTEXPR typename normalise<policy<>, A1>::type make_policy(const A1&) BOOST_NOEXCEPT
  615. {
  616. typedef typename normalise<policy<>, A1>::type result_type;
  617. return result_type();
  618. }
  619. template <class A1, class A2>
  620. inline BOOST_MATH_CONSTEXPR typename normalise<policy<>, A1, A2>::type make_policy(const A1&, const A2&) BOOST_NOEXCEPT
  621. {
  622. typedef typename normalise<policy<>, A1, A2>::type result_type;
  623. return result_type();
  624. }
  625. template <class A1, class A2, class A3>
  626. inline BOOST_MATH_CONSTEXPR typename normalise<policy<>, A1, A2, A3>::type make_policy(const A1&, const A2&, const A3&) BOOST_NOEXCEPT
  627. {
  628. typedef typename normalise<policy<>, A1, A2, A3>::type result_type;
  629. return result_type();
  630. }
  631. template <class A1, class A2, class A3, class A4>
  632. inline BOOST_MATH_CONSTEXPR typename normalise<policy<>, A1, A2, A3, A4>::type make_policy(const A1&, const A2&, const A3&, const A4&) BOOST_NOEXCEPT
  633. {
  634. typedef typename normalise<policy<>, A1, A2, A3, A4>::type result_type;
  635. return result_type();
  636. }
  637. template <class A1, class A2, class A3, class A4, class A5>
  638. 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
  639. {
  640. typedef typename normalise<policy<>, A1, A2, A3, A4, A5>::type result_type;
  641. return result_type();
  642. }
  643. template <class A1, class A2, class A3, class A4, class A5, class A6>
  644. 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
  645. {
  646. typedef typename normalise<policy<>, A1, A2, A3, A4, A5, A6>::type result_type;
  647. return result_type();
  648. }
  649. template <class A1, class A2, class A3, class A4, class A5, class A6, class A7>
  650. 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
  651. {
  652. typedef typename normalise<policy<>, A1, A2, A3, A4, A5, A6, A7>::type result_type;
  653. return result_type();
  654. }
  655. template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
  656. 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
  657. {
  658. typedef typename normalise<policy<>, A1, A2, A3, A4, A5, A6, A7, A8>::type result_type;
  659. return result_type();
  660. }
  661. template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
  662. 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
  663. {
  664. typedef typename normalise<policy<>, A1, A2, A3, A4, A5, A6, A7, A8, A9>::type result_type;
  665. return result_type();
  666. }
  667. template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10>
  668. 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
  669. {
  670. typedef typename normalise<policy<>, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10>::type result_type;
  671. return result_type();
  672. }
  673. template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11>
  674. 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
  675. {
  676. typedef typename normalise<policy<>, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11>::type result_type;
  677. return result_type();
  678. }
  679. //
  680. // Traits class to handle internal promotion:
  681. //
  682. template <class Real, class Policy>
  683. struct evaluation
  684. {
  685. typedef Real type;
  686. };
  687. template <class Policy>
  688. struct evaluation<float, Policy>
  689. {
  690. typedef typename mpl::if_<typename Policy::promote_float_type, double, float>::type type;
  691. };
  692. template <class Policy>
  693. struct evaluation<double, Policy>
  694. {
  695. typedef typename mpl::if_<typename Policy::promote_double_type, long double, double>::type type;
  696. };
  697. #ifdef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
  698. template <class Real>
  699. struct basic_digits : public mpl::int_<0>{ };
  700. template <>
  701. struct basic_digits<float> : public mpl::int_<FLT_MANT_DIG>{ };
  702. template <>
  703. struct basic_digits<double> : public mpl::int_<DBL_MANT_DIG>{ };
  704. template <>
  705. struct basic_digits<long double> : public mpl::int_<LDBL_MANT_DIG>{ };
  706. template <class Real, class Policy>
  707. struct precision
  708. {
  709. BOOST_STATIC_ASSERT( ::std::numeric_limits<Real>::radix == 2);
  710. typedef typename Policy::precision_type precision_type;
  711. typedef basic_digits<Real> digits_t;
  712. typedef typename mpl::if_<
  713. mpl::equal_to<digits_t, mpl::int_<0> >,
  714. // Possibly unknown precision:
  715. precision_type,
  716. typename mpl::if_<
  717. mpl::or_<mpl::less_equal<digits_t, precision_type>, mpl::less_equal<precision_type, mpl::int_<0> > >,
  718. // Default case, full precision for RealType:
  719. digits2< ::std::numeric_limits<Real>::digits>,
  720. // User customised precision:
  721. precision_type
  722. >::type
  723. >::type type;
  724. };
  725. template <class Policy>
  726. struct precision<float, Policy>
  727. {
  728. typedef digits2<FLT_MANT_DIG> type;
  729. };
  730. template <class Policy>
  731. struct precision<double, Policy>
  732. {
  733. typedef digits2<DBL_MANT_DIG> type;
  734. };
  735. template <class Policy>
  736. struct precision<long double, Policy>
  737. {
  738. typedef digits2<LDBL_MANT_DIG> type;
  739. };
  740. #else
  741. template <class Real, class Policy>
  742. struct precision
  743. {
  744. BOOST_STATIC_ASSERT((::std::numeric_limits<Real>::radix == 2) || ((::std::numeric_limits<Real>::is_specialized == 0) || (::std::numeric_limits<Real>::digits == 0)));
  745. #ifndef __BORLANDC__
  746. typedef typename Policy::precision_type precision_type;
  747. typedef typename mpl::if_c<
  748. ((::std::numeric_limits<Real>::is_specialized == 0) || (::std::numeric_limits<Real>::digits == 0)),
  749. // Possibly unknown precision:
  750. precision_type,
  751. typename mpl::if_c<
  752. ((::std::numeric_limits<Real>::digits <= precision_type::value)
  753. || (Policy::precision_type::value <= 0)),
  754. // Default case, full precision for RealType:
  755. digits2< ::std::numeric_limits<Real>::digits>,
  756. // User customised precision:
  757. precision_type
  758. >::type
  759. >::type type;
  760. #else
  761. typedef typename Policy::precision_type precision_type;
  762. typedef mpl::int_< ::std::numeric_limits<Real>::digits> digits_t;
  763. typedef mpl::bool_< ::std::numeric_limits<Real>::is_specialized> spec_t;
  764. typedef typename mpl::if_<
  765. mpl::or_<mpl::equal_to<spec_t, mpl::false_>, mpl::equal_to<digits_t, mpl::int_<0> > >,
  766. // Possibly unknown precision:
  767. precision_type,
  768. typename mpl::if_<
  769. mpl::or_<mpl::less_equal<digits_t, precision_type>, mpl::less_equal<precision_type, mpl::int_<0> > >,
  770. // Default case, full precision for RealType:
  771. digits2< ::std::numeric_limits<Real>::digits>,
  772. // User customised precision:
  773. precision_type
  774. >::type
  775. >::type type;
  776. #endif
  777. };
  778. #endif
  779. #ifdef BOOST_MATH_USE_FLOAT128
  780. template <class Policy>
  781. struct precision<BOOST_MATH_FLOAT128_TYPE, Policy>
  782. {
  783. typedef mpl::int_<113> type;
  784. };
  785. #endif
  786. namespace detail{
  787. template <class T, class Policy>
  788. inline BOOST_MATH_CONSTEXPR int digits_imp(mpl::true_ const&) BOOST_NOEXCEPT
  789. {
  790. #ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
  791. BOOST_STATIC_ASSERT( ::std::numeric_limits<T>::is_specialized);
  792. #else
  793. BOOST_ASSERT(::std::numeric_limits<T>::is_specialized);
  794. #endif
  795. typedef typename boost::math::policies::precision<T, Policy>::type p_t;
  796. return p_t::value;
  797. }
  798. template <class T, class Policy>
  799. inline BOOST_MATH_CONSTEXPR int digits_imp(mpl::false_ const&) BOOST_NOEXCEPT
  800. {
  801. return tools::digits<T>();
  802. }
  803. } // namespace detail
  804. template <class T, class Policy>
  805. inline BOOST_MATH_CONSTEXPR int digits(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(T)) BOOST_NOEXCEPT
  806. {
  807. typedef mpl::bool_< std::numeric_limits<T>::is_specialized > tag_type;
  808. return detail::digits_imp<T, Policy>(tag_type());
  809. }
  810. template <class T, class Policy>
  811. inline BOOST_MATH_CONSTEXPR int digits_base10(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(T)) BOOST_NOEXCEPT
  812. {
  813. return boost::math::policies::digits<T, Policy>() * 301 / 1000L;
  814. }
  815. template <class Policy>
  816. inline BOOST_MATH_CONSTEXPR unsigned long get_max_series_iterations() BOOST_NOEXCEPT
  817. {
  818. typedef typename Policy::max_series_iterations_type iter_type;
  819. return iter_type::value;
  820. }
  821. template <class Policy>
  822. inline BOOST_MATH_CONSTEXPR unsigned long get_max_root_iterations() BOOST_NOEXCEPT
  823. {
  824. typedef typename Policy::max_root_iterations_type iter_type;
  825. return iter_type::value;
  826. }
  827. namespace detail{
  828. template <class T, class Digits, class Small, class Default>
  829. struct series_factor_calc
  830. {
  831. static T get() BOOST_MATH_NOEXCEPT(T)
  832. {
  833. return ldexp(T(1.0), 1 - Digits::value);
  834. }
  835. };
  836. template <class T, class Digits>
  837. struct series_factor_calc<T, Digits, mpl::true_, mpl::true_>
  838. {
  839. static BOOST_MATH_CONSTEXPR T get() BOOST_MATH_NOEXCEPT(T)
  840. {
  841. return boost::math::tools::epsilon<T>();
  842. }
  843. };
  844. template <class T, class Digits>
  845. struct series_factor_calc<T, Digits, mpl::true_, mpl::false_>
  846. {
  847. static BOOST_MATH_CONSTEXPR T get() BOOST_MATH_NOEXCEPT(T)
  848. {
  849. return 1 / static_cast<T>(static_cast<boost::uintmax_t>(1u) << (Digits::value - 1));
  850. }
  851. };
  852. template <class T, class Digits>
  853. struct series_factor_calc<T, Digits, mpl::false_, mpl::true_>
  854. {
  855. static BOOST_MATH_CONSTEXPR T get() BOOST_MATH_NOEXCEPT(T)
  856. {
  857. return boost::math::tools::epsilon<T>();
  858. }
  859. };
  860. template <class T, class Policy>
  861. inline BOOST_MATH_CONSTEXPR T get_epsilon_imp(mpl::true_ const&) BOOST_MATH_NOEXCEPT(T)
  862. {
  863. #ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
  864. BOOST_STATIC_ASSERT( ::std::numeric_limits<T>::is_specialized);
  865. BOOST_STATIC_ASSERT( ::std::numeric_limits<T>::radix == 2);
  866. #else
  867. BOOST_ASSERT(::std::numeric_limits<T>::is_specialized);
  868. BOOST_ASSERT(::std::numeric_limits<T>::radix == 2);
  869. #endif
  870. typedef typename boost::math::policies::precision<T, Policy>::type p_t;
  871. typedef mpl::bool_<p_t::value <= std::numeric_limits<boost::uintmax_t>::digits> is_small_int;
  872. typedef mpl::bool_<p_t::value >= std::numeric_limits<T>::digits> is_default_value;
  873. return series_factor_calc<T, p_t, is_small_int, is_default_value>::get();
  874. }
  875. template <class T, class Policy>
  876. inline BOOST_MATH_CONSTEXPR T get_epsilon_imp(mpl::false_ const&) BOOST_MATH_NOEXCEPT(T)
  877. {
  878. return tools::epsilon<T>();
  879. }
  880. } // namespace detail
  881. template <class T, class Policy>
  882. inline BOOST_MATH_CONSTEXPR T get_epsilon(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(T)) BOOST_MATH_NOEXCEPT(T)
  883. {
  884. typedef mpl::bool_< (std::numeric_limits<T>::is_specialized && (std::numeric_limits<T>::radix == 2)) > tag_type;
  885. return detail::get_epsilon_imp<T, Policy>(tag_type());
  886. }
  887. namespace detail{
  888. template <class A1,
  889. class A2,
  890. class A3,
  891. class A4,
  892. class A5,
  893. class A6,
  894. class A7,
  895. class A8,
  896. class A9,
  897. class A10,
  898. class A11>
  899. char test_is_policy(const policy<A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11>*);
  900. double test_is_policy(...);
  901. template <class P>
  902. struct is_policy_imp
  903. {
  904. BOOST_STATIC_CONSTANT(bool, value = (sizeof(::boost::math::policies::detail::test_is_policy(static_cast<P*>(0))) == 1));
  905. };
  906. }
  907. template <class P>
  908. struct is_policy : public mpl::bool_< ::boost::math::policies::detail::is_policy_imp<P>::value> {};
  909. //
  910. // Helper traits class for distribution error handling:
  911. //
  912. template <class Policy>
  913. struct constructor_error_check
  914. {
  915. typedef typename Policy::domain_error_type domain_error_type;
  916. typedef typename mpl::if_c<
  917. (domain_error_type::value == throw_on_error) || (domain_error_type::value == user_error) || (domain_error_type::value == errno_on_error),
  918. mpl::true_,
  919. mpl::false_>::type type;
  920. };
  921. template <class Policy>
  922. struct method_error_check
  923. {
  924. typedef typename Policy::domain_error_type domain_error_type;
  925. typedef typename mpl::if_c<
  926. (domain_error_type::value == throw_on_error) && (domain_error_type::value != user_error),
  927. mpl::false_,
  928. mpl::true_>::type type;
  929. };
  930. //
  931. // Does the Policy ever throw on error?
  932. //
  933. template <class Policy>
  934. struct is_noexcept_error_policy
  935. {
  936. typedef typename Policy::domain_error_type t1;
  937. typedef typename Policy::pole_error_type t2;
  938. typedef typename Policy::overflow_error_type t3;
  939. typedef typename Policy::underflow_error_type t4;
  940. typedef typename Policy::denorm_error_type t5;
  941. typedef typename Policy::evaluation_error_type t6;
  942. typedef typename Policy::rounding_error_type t7;
  943. typedef typename Policy::indeterminate_result_error_type t8;
  944. BOOST_STATIC_CONSTANT(bool, value =
  945. ((t1::value != throw_on_error) && (t1::value != user_error)
  946. && (t2::value != throw_on_error) && (t2::value != user_error)
  947. && (t3::value != throw_on_error) && (t3::value != user_error)
  948. && (t4::value != throw_on_error) && (t4::value != user_error)
  949. && (t5::value != throw_on_error) && (t5::value != user_error)
  950. && (t6::value != throw_on_error) && (t6::value != user_error)
  951. && (t7::value != throw_on_error) && (t7::value != user_error)
  952. && (t8::value != throw_on_error) && (t8::value != user_error)));
  953. };
  954. }}} // namespaces
  955. #endif // BOOST_MATH_POLICY_HPP