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