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