]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/math/test/test_error_handling.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / math / test / test_error_handling.cpp
1 // Copyright Paul A. Bristow 2006-7.
2 // Copyright John Maddock 2006-7.
3
4 // Use, modification and distribution are subject to the
5 // Boost Software License, Version 1.0.
6 // (See accompanying file LICENSE_1_0.txt
7 // or copy at http://www.boost.org/LICENSE_1_0.txt)
8
9 // Test error handling mechanism produces the expected error messages.
10 // for example Error in function boost::math::test_function<float>(float, float, float): Domain Error evaluating function at 0
11
12 // Define some custom dummy error handlers that do nothing but throw,
13 // in order to check that they are otherwise undefined.
14 // The user MUST define them before they can be used.
15 //
16 struct user_defined_error{};
17
18 namespace boost{ namespace math{ namespace policies{
19
20 #ifndef BOOST_NO_EXCEPTIONS
21
22 template <class T>
23 T user_domain_error(const char* , const char* , const T& )
24 {
25 throw user_defined_error();
26 }
27
28 template <class T>
29 T user_pole_error(const char* , const char* , const T& )
30 {
31 throw user_defined_error();
32 }
33
34 template <class T>
35 T user_overflow_error(const char* , const char* , const T& )
36 {
37 throw user_defined_error();
38 }
39
40 template <class T>
41 T user_underflow_error(const char* , const char* , const T& )
42 {
43 throw user_defined_error();
44 }
45
46 template <class T>
47 T user_denorm_error(const char* , const char* , const T& )
48 {
49 throw user_defined_error();
50 }
51
52 template <class T>
53 T user_evaluation_error(const char* , const char* , const T& )
54 {
55 throw user_defined_error();
56 }
57
58 template <class T>
59 T user_indeterminate_result_error(const char* , const char* , const T& )
60 {
61 throw user_defined_error();
62 }
63 #endif
64 }}} // namespaces
65
66 #include <boost/math/tools/test.hpp>
67 #include <boost/math/concepts/real_concept.hpp>
68 #include <boost/math/policies/policy.hpp>
69 #include <boost/math/policies/error_handling.hpp>
70 #include <boost/math/tools/polynomial.hpp>
71 #define BOOST_TEST_MAIN
72 #include <boost/test/unit_test.hpp> // for test_main
73 #include <cerrno> // for errno
74 #include <iostream>
75 #include <iomanip>
76 //
77 // Define some policies:
78 //
79 using namespace boost::math::policies;
80 policy<
81 domain_error<throw_on_error>,
82 pole_error<throw_on_error>,
83 overflow_error<throw_on_error>,
84 underflow_error<throw_on_error>,
85 denorm_error<throw_on_error>,
86 evaluation_error<throw_on_error>,
87 indeterminate_result_error<throw_on_error> > throw_policy;
88 policy<
89 domain_error<errno_on_error>,
90 pole_error<errno_on_error>,
91 overflow_error<errno_on_error>,
92 underflow_error<errno_on_error>,
93 denorm_error<errno_on_error>,
94 evaluation_error<errno_on_error>,
95 indeterminate_result_error<errno_on_error> > errno_policy;
96 policy<
97 domain_error<ignore_error>,
98 pole_error<ignore_error>,
99 overflow_error<ignore_error>,
100 underflow_error<ignore_error>,
101 denorm_error<ignore_error>,
102 evaluation_error<ignore_error>,
103 indeterminate_result_error<ignore_error> > ignore_policy;
104 policy<
105 domain_error<user_error>,
106 pole_error<user_error>,
107 overflow_error<user_error>,
108 underflow_error<user_error>,
109 denorm_error<user_error>,
110 evaluation_error<user_error>,
111 indeterminate_result_error<user_error> > user_policy;
112 policy<> default_policy;
113
114 #define TEST_EXCEPTION(expression, exception, msg)\
115 BOOST_MATH_CHECK_THROW(expression, exception);\
116 try{ expression; }catch(const exception& e){ std::cout << e.what() << std::endl; BOOST_CHECK_EQUAL(std::string(e.what()), std::string(msg)); }
117
118 template <class T>
119 std::string format_message_string(const char* str)
120 {
121 std::string type_name = boost::math::policies::detail::name_of<T>();
122 std::string result(str);
123 if(type_name != "float")
124 {
125 std::string::size_type pos = 0;
126 while((pos = result.find("float", pos)) != std::string::npos)
127 {
128 result.replace(pos, 5, type_name);
129 pos += type_name.size();
130 }
131 }
132 return result;
133 }
134
135 template <class T>
136 void test_error(T)
137 {
138 const char* func = "boost::math::test_function<%1%>(%1%, %1%, %1%)";
139 const char* msg1 = "Error while handling value %1%";
140 const char* msg2 = "Error message goes here...";
141
142 // Check that exception is thrown, catch and show the message, for example:
143 // Error in function boost::math::test_function<float>(float, float, float): Error while handling value 0
144 #ifndef BOOST_NO_EXCEPTIONS
145 TEST_EXCEPTION(boost::math::policies::raise_domain_error(func, msg1, T(0.0), throw_policy), std::domain_error, format_message_string<T>("Error in function boost::math::test_function<float>(float, float, float): Error while handling value 0"));
146 TEST_EXCEPTION(boost::math::policies::raise_domain_error(func, 0, T(0.0), throw_policy), std::domain_error, format_message_string<T>("Error in function boost::math::test_function<float>(float, float, float): Domain Error evaluating function at 0"));
147 TEST_EXCEPTION(boost::math::policies::raise_pole_error(func, msg1, T(0.0), throw_policy), std::domain_error, format_message_string<T>("Error in function boost::math::test_function<float>(float, float, float): Error while handling value 0"));
148 TEST_EXCEPTION(boost::math::policies::raise_pole_error(func, 0, T(0.0), throw_policy), std::domain_error, format_message_string<T>("Error in function boost::math::test_function<float>(float, float, float): Evaluation of function at pole 0"));
149 TEST_EXCEPTION(boost::math::policies::raise_overflow_error<T>(func, msg2, throw_policy), std::overflow_error, format_message_string<T>("Error in function boost::math::test_function<float>(float, float, float): Error message goes here..."));
150 TEST_EXCEPTION(boost::math::policies::raise_overflow_error<T>(func, 0, throw_policy), std::overflow_error, format_message_string<T>("Error in function boost::math::test_function<float>(float, float, float): Overflow Error"));
151 TEST_EXCEPTION(boost::math::policies::raise_underflow_error<T>(func, msg2, throw_policy), std::underflow_error, format_message_string<T>("Error in function boost::math::test_function<float>(float, float, float): Error message goes here..."));
152 TEST_EXCEPTION(boost::math::policies::raise_underflow_error<T>(func, 0, throw_policy), std::underflow_error, format_message_string<T>("Error in function boost::math::test_function<float>(float, float, float): Underflow Error"));
153 TEST_EXCEPTION(boost::math::policies::raise_denorm_error<T>(func, msg2, T(0), throw_policy), std::underflow_error, format_message_string<T>("Error in function boost::math::test_function<float>(float, float, float): Error message goes here..."));
154 TEST_EXCEPTION(boost::math::policies::raise_denorm_error<T>(func, 0, T(0), throw_policy), std::underflow_error, format_message_string<T>("Error in function boost::math::test_function<float>(float, float, float): Denorm Error"));
155 TEST_EXCEPTION(boost::math::policies::raise_evaluation_error(func, msg1, T(1.25), throw_policy), boost::math::evaluation_error, format_message_string<T>("Error in function boost::math::test_function<float>(float, float, float): Error while handling value 1.25"));
156 TEST_EXCEPTION(boost::math::policies::raise_evaluation_error(func, 0, T(1.25), throw_policy), boost::math::evaluation_error, format_message_string<T>("Error in function boost::math::test_function<float>(float, float, float): Internal Evaluation Error, best value so far was 1.25"));
157 TEST_EXCEPTION(boost::math::policies::raise_indeterminate_result_error(func, msg1, T(1.25), T(12.34), throw_policy), std::domain_error, format_message_string<T>("Error in function boost::math::test_function<float>(float, float, float): Error while handling value 1.25"));
158 TEST_EXCEPTION(boost::math::policies::raise_indeterminate_result_error(func, 0, T(1.25), T(12.34), throw_policy), std::domain_error, format_message_string<T>("Error in function boost::math::test_function<float>(float, float, float): Indeterminate result with value 1.25"));
159 //
160 // Now try user error handlers: these should all throw user_error():
161 // - because by design these are undefined and must be defined by the user ;-)
162 BOOST_MATH_CHECK_THROW(boost::math::policies::raise_domain_error(func, msg1, T(0.0), user_policy), user_defined_error);
163 BOOST_MATH_CHECK_THROW(boost::math::policies::raise_pole_error(func, msg1, T(0.0), user_policy), user_defined_error);
164 BOOST_MATH_CHECK_THROW(boost::math::policies::raise_overflow_error<T>(func, msg2, user_policy), user_defined_error);
165 BOOST_MATH_CHECK_THROW(boost::math::policies::raise_underflow_error<T>(func, msg2, user_policy), user_defined_error);
166 BOOST_MATH_CHECK_THROW(boost::math::policies::raise_denorm_error<T>(func, msg2, T(0), user_policy), user_defined_error);
167 BOOST_MATH_CHECK_THROW(boost::math::policies::raise_evaluation_error(func, msg1, T(0.0), user_policy), user_defined_error);
168 BOOST_MATH_CHECK_THROW(boost::math::policies::raise_indeterminate_result_error(func, msg1, T(0.0), T(0.0), user_policy), user_defined_error);
169 #endif
170
171 // Test with ignore_error
172 BOOST_CHECK((boost::math::isnan)(boost::math::policies::raise_domain_error(func, msg1, T(0.0), ignore_policy)) || !std::numeric_limits<T>::has_quiet_NaN);
173 BOOST_CHECK((boost::math::isnan)(boost::math::policies::raise_pole_error(func, msg1, T(0.0), ignore_policy)) || !std::numeric_limits<T>::has_quiet_NaN);
174 BOOST_CHECK_EQUAL(boost::math::policies::raise_overflow_error<T>(func, msg2, ignore_policy), std::numeric_limits<T>::has_infinity ? std::numeric_limits<T>::infinity() : boost::math::tools::max_value<T>());
175 BOOST_CHECK_EQUAL(boost::math::policies::raise_underflow_error<T>(func, msg2, ignore_policy), T(0));
176 BOOST_CHECK_EQUAL(boost::math::policies::raise_denorm_error<T>(func, msg2, T(1.25), ignore_policy), T(1.25));
177 BOOST_CHECK_EQUAL(boost::math::policies::raise_evaluation_error(func, msg1, T(1.25), ignore_policy), T(1.25));
178 BOOST_CHECK_EQUAL(boost::math::policies::raise_indeterminate_result_error(func, 0, T(0.0), T(12.34), ignore_policy), T(12.34));
179
180 // Test with errno_on_error
181 errno = 0;
182 BOOST_CHECK((boost::math::isnan)(boost::math::policies::raise_domain_error(func, msg1, T(0.0), errno_policy)) || !std::numeric_limits<T>::has_quiet_NaN);
183 BOOST_CHECK(errno == EDOM);
184 errno = 0;
185 BOOST_CHECK((boost::math::isnan)(boost::math::policies::raise_pole_error(func, msg1, T(0.0), errno_policy)) || !std::numeric_limits<T>::has_quiet_NaN);
186 BOOST_CHECK(errno == EDOM);
187 errno = 0;
188 BOOST_CHECK_EQUAL(boost::math::policies::raise_overflow_error<T>(func, msg2, errno_policy), std::numeric_limits<T>::has_infinity ? std::numeric_limits<T>::infinity() : boost::math::tools::max_value<T>());
189 BOOST_CHECK_EQUAL(errno, ERANGE);
190 errno = 0;
191 BOOST_CHECK_EQUAL(boost::math::policies::raise_underflow_error<T>(func, msg2, errno_policy), T(0));
192 BOOST_CHECK_EQUAL(errno, ERANGE);
193 errno = 0;
194 BOOST_CHECK_EQUAL(boost::math::policies::raise_denorm_error<T>(func, msg2, T(1.25), errno_policy), T(1.25));
195 BOOST_CHECK_EQUAL(errno, ERANGE);
196 errno = 0;
197 BOOST_CHECK_EQUAL(boost::math::policies::raise_evaluation_error(func, msg1, T(1.25), errno_policy), T(1.25));
198 BOOST_CHECK(errno == EDOM);
199 errno = 0;
200 BOOST_CHECK(boost::math::policies::raise_indeterminate_result_error(func, 0, T(0.0), T(12.34), errno_policy) == T(12.34));
201 BOOST_CHECK_EQUAL(errno, EDOM);
202 }
203
204 template <class T>
205 void test_complex_error(T)
206 {
207 //
208 // Error handling that can be applied to non-scalar types such as std::complex
209 //
210 const char* func = "boost::math::test_function<%1%>(%1%, %1%, %1%)";
211 const char* msg1 = "Error while handling value %1%";
212 const char* msg2 = "Error message goes here...";
213
214 // Check that exception is thrown, catch and show the message, for example:
215 // Error in function boost::math::test_function<float>(float, float, float): Error while handling value 0
216 #ifndef BOOST_NO_EXCEPTIONS
217 TEST_EXCEPTION(boost::math::policies::raise_domain_error(func, msg1, T(0.0), throw_policy), std::domain_error, format_message_string<T>("Error in function boost::math::test_function<float>(float, float, float): Error while handling value (0,0)"));
218 TEST_EXCEPTION(boost::math::policies::raise_domain_error(func, 0, T(0.0), throw_policy), std::domain_error, format_message_string<T>("Error in function boost::math::test_function<float>(float, float, float): Domain Error evaluating function at (0,0)"));
219 TEST_EXCEPTION(boost::math::policies::raise_pole_error(func, msg1, T(0.0), throw_policy), std::domain_error, format_message_string<T>("Error in function boost::math::test_function<float>(float, float, float): Error while handling value (0,0)"));
220 TEST_EXCEPTION(boost::math::policies::raise_pole_error(func, 0, T(0.0), throw_policy), std::domain_error, format_message_string<T>("Error in function boost::math::test_function<float>(float, float, float): Evaluation of function at pole (0,0)"));
221 //TEST_EXCEPTION(boost::math::policies::raise_overflow_error<T>(func, msg2, throw_policy), std::overflow_error, format_message_string<T>("Error in function boost::math::test_function<float>(float, float, float): Error message goes here..."));
222 //TEST_EXCEPTION(boost::math::policies::raise_overflow_error<T>(func, 0, throw_policy), std::overflow_error, format_message_string<T>("Error in function boost::math::test_function<float>(float, float, float): Overflow Error"));
223 TEST_EXCEPTION(boost::math::policies::raise_underflow_error<T>(func, msg2, throw_policy), std::underflow_error, format_message_string<T>("Error in function boost::math::test_function<float>(float, float, float): Error message goes here..."));
224 TEST_EXCEPTION(boost::math::policies::raise_underflow_error<T>(func, 0, throw_policy), std::underflow_error, format_message_string<T>("Error in function boost::math::test_function<float>(float, float, float): Underflow Error"));
225 TEST_EXCEPTION(boost::math::policies::raise_denorm_error<T>(func, msg2, T(0), throw_policy), std::underflow_error, format_message_string<T>("Error in function boost::math::test_function<float>(float, float, float): Error message goes here..."));
226 TEST_EXCEPTION(boost::math::policies::raise_denorm_error<T>(func, 0, T(0), throw_policy), std::underflow_error, format_message_string<T>("Error in function boost::math::test_function<float>(float, float, float): Denorm Error"));
227 TEST_EXCEPTION(boost::math::policies::raise_evaluation_error(func, msg1, T(1.25), throw_policy), boost::math::evaluation_error, format_message_string<T>("Error in function boost::math::test_function<float>(float, float, float): Error while handling value (1.25,0)"));
228 TEST_EXCEPTION(boost::math::policies::raise_evaluation_error(func, 0, T(1.25), throw_policy), boost::math::evaluation_error, format_message_string<T>("Error in function boost::math::test_function<float>(float, float, float): Internal Evaluation Error, best value so far was (1.25,0)"));
229 TEST_EXCEPTION(boost::math::policies::raise_indeterminate_result_error(func, msg1, T(1.25), T(12.34), throw_policy), std::domain_error, format_message_string<T>("Error in function boost::math::test_function<float>(float, float, float): Error while handling value (1.25,0)"));
230 TEST_EXCEPTION(boost::math::policies::raise_indeterminate_result_error(func, 0, T(1.25), T(12.34), throw_policy), std::domain_error, format_message_string<T>("Error in function boost::math::test_function<float>(float, float, float): Indeterminate result with value (1.25,0)"));
231 //
232 // Now try user error handlers: these should all throw user_error():
233 // - because by design these are undefined and must be defined by the user ;-)
234 BOOST_MATH_CHECK_THROW(boost::math::policies::raise_domain_error(func, msg1, T(0.0), user_policy), user_defined_error);
235 BOOST_MATH_CHECK_THROW(boost::math::policies::raise_pole_error(func, msg1, T(0.0), user_policy), user_defined_error);
236 //BOOST_MATH_CHECK_THROW(boost::math::policies::raise_overflow_error<T>(func, msg2, user_policy), user_defined_error);
237 BOOST_MATH_CHECK_THROW(boost::math::policies::raise_underflow_error<T>(func, msg2, user_policy), user_defined_error);
238 BOOST_MATH_CHECK_THROW(boost::math::policies::raise_denorm_error<T>(func, msg2, T(0), user_policy), user_defined_error);
239 BOOST_MATH_CHECK_THROW(boost::math::policies::raise_evaluation_error(func, msg1, T(0.0), user_policy), user_defined_error);
240 BOOST_MATH_CHECK_THROW(boost::math::policies::raise_indeterminate_result_error(func, msg1, T(0.0), T(0.0), user_policy), user_defined_error);
241 #endif
242
243 // Test with ignore_error
244 BOOST_CHECK((boost::math::isnan)(boost::math::policies::raise_domain_error(func, msg1, T(0.0), ignore_policy)) || !std::numeric_limits<T>::has_quiet_NaN);
245 BOOST_CHECK((boost::math::isnan)(boost::math::policies::raise_pole_error(func, msg1, T(0.0), ignore_policy)) || !std::numeric_limits<T>::has_quiet_NaN);
246 //BOOST_CHECK_EQUAL(boost::math::policies::raise_overflow_error<T>(func, msg2, ignore_policy), std::numeric_limits<T>::has_infinity ? std::numeric_limits<T>::infinity() : boost::math::tools::max_value<T>());
247 BOOST_CHECK_EQUAL(boost::math::policies::raise_underflow_error<T>(func, msg2, ignore_policy), T(0));
248 BOOST_CHECK_EQUAL(boost::math::policies::raise_denorm_error<T>(func, msg2, T(1.25), ignore_policy), T(1.25));
249 BOOST_CHECK_EQUAL(boost::math::policies::raise_evaluation_error(func, msg1, T(1.25), ignore_policy), T(1.25));
250 BOOST_CHECK_EQUAL(boost::math::policies::raise_indeterminate_result_error(func, 0, T(0.0), T(12.34), ignore_policy), T(12.34));
251
252 // Test with errno_on_error
253 errno = 0;
254 BOOST_CHECK((boost::math::isnan)(boost::math::policies::raise_domain_error(func, msg1, T(0.0), errno_policy)) || !std::numeric_limits<T>::has_quiet_NaN);
255 BOOST_CHECK(errno == EDOM);
256 errno = 0;
257 BOOST_CHECK((boost::math::isnan)(boost::math::policies::raise_pole_error(func, msg1, T(0.0), errno_policy)) || !std::numeric_limits<T>::has_quiet_NaN);
258 BOOST_CHECK(errno == EDOM);
259 errno = 0;
260 //BOOST_CHECK_EQUAL(boost::math::policies::raise_overflow_error<T>(func, msg2, errno_policy), std::numeric_limits<T>::has_infinity ? std::numeric_limits<T>::infinity() : boost::math::tools::max_value<T>());
261 //BOOST_CHECK_EQUAL(errno, ERANGE);
262 errno = 0;
263 BOOST_CHECK_EQUAL(boost::math::policies::raise_underflow_error<T>(func, msg2, errno_policy), T(0));
264 BOOST_CHECK_EQUAL(errno, ERANGE);
265 errno = 0;
266 BOOST_CHECK_EQUAL(boost::math::policies::raise_denorm_error<T>(func, msg2, T(1.25), errno_policy), T(1.25));
267 BOOST_CHECK_EQUAL(errno, ERANGE);
268 errno = 0;
269 BOOST_CHECK_EQUAL(boost::math::policies::raise_evaluation_error(func, msg1, T(1.25), errno_policy), T(1.25));
270 BOOST_CHECK(errno == EDOM);
271 errno = 0;
272 BOOST_CHECK(boost::math::policies::raise_indeterminate_result_error(func, 0, T(0.0), T(12.34), errno_policy) == T(12.34));
273 BOOST_CHECK_EQUAL(errno, EDOM);
274 }
275
276 template <class T>
277 void test_polynomial_error(T)
278 {
279 //
280 // Error handling that can be applied to non-scalar types such as std::complex
281 //
282 const char* func = "boost::math::test_function<%1%>(%1%, %1%, %1%)";
283 const char* msg1 = "Error while handling value %1%";
284
285 static const typename T::value_type data[] = { 1, 2, 3 };
286 static const T val(data, 2);
287
288 // Check that exception is thrown, catch and show the message, for example:
289 // Error in function boost::math::test_function<float>(float, float, float): Error while handling value 0
290 #ifndef BOOST_NO_EXCEPTIONS
291 TEST_EXCEPTION(boost::math::policies::raise_domain_error(func, msg1, val, throw_policy), std::domain_error, format_message_string<T>("Error in function boost::math::test_function<float>(float, float, float): Error while handling value { 1, 2, 3 }"));
292 TEST_EXCEPTION(boost::math::policies::raise_domain_error(func, 0, val, throw_policy), std::domain_error, format_message_string<T>("Error in function boost::math::test_function<float>(float, float, float): Domain Error evaluating function at { 1, 2, 3 }"));
293 TEST_EXCEPTION(boost::math::policies::raise_pole_error(func, msg1, val, throw_policy), std::domain_error, format_message_string<T>("Error in function boost::math::test_function<float>(float, float, float): Error while handling value { 1, 2, 3 }"));
294 TEST_EXCEPTION(boost::math::policies::raise_pole_error(func, 0, val, throw_policy), std::domain_error, format_message_string<T>("Error in function boost::math::test_function<float>(float, float, float): Evaluation of function at pole { 1, 2, 3 }"));
295 TEST_EXCEPTION(boost::math::policies::raise_evaluation_error(func, msg1, val, throw_policy), boost::math::evaluation_error, format_message_string<T>("Error in function boost::math::test_function<float>(float, float, float): Error while handling value { 1, 2, 3 }"));
296 TEST_EXCEPTION(boost::math::policies::raise_evaluation_error(func, 0, val, throw_policy), boost::math::evaluation_error, format_message_string<T>("Error in function boost::math::test_function<float>(float, float, float): Internal Evaluation Error, best value so far was { 1, 2, 3 }"));
297 TEST_EXCEPTION(boost::math::policies::raise_indeterminate_result_error(func, msg1, val, T(12.34), throw_policy), std::domain_error, format_message_string<T>("Error in function boost::math::test_function<float>(float, float, float): Error while handling value { 1, 2, 3 }"));
298 TEST_EXCEPTION(boost::math::policies::raise_indeterminate_result_error(func, 0, val, T(12.34), throw_policy), std::domain_error, format_message_string<T>("Error in function boost::math::test_function<float>(float, float, float): Indeterminate result with value { 1, 2, 3 }"));
299 //
300 // Now try user error handlers: these should all throw user_error():
301 // - because by design these are undefined and must be defined by the user ;-)
302 BOOST_MATH_CHECK_THROW(boost::math::policies::raise_domain_error(func, msg1, T(0.0), user_policy), user_defined_error);
303 BOOST_MATH_CHECK_THROW(boost::math::policies::raise_pole_error(func, msg1, T(0.0), user_policy), user_defined_error);
304 BOOST_MATH_CHECK_THROW(boost::math::policies::raise_evaluation_error(func, msg1, T(0.0), user_policy), user_defined_error);
305 BOOST_MATH_CHECK_THROW(boost::math::policies::raise_indeterminate_result_error(func, msg1, T(0.0), T(0.0), user_policy), user_defined_error);
306 #endif
307
308 // Test with ignore_error
309 BOOST_CHECK((boost::math::isnan)(boost::math::policies::raise_domain_error(func, msg1, T(0.0), ignore_policy)) || !std::numeric_limits<T>::has_quiet_NaN);
310 BOOST_CHECK((boost::math::isnan)(boost::math::policies::raise_pole_error(func, msg1, T(0.0), ignore_policy)) || !std::numeric_limits<T>::has_quiet_NaN);
311 BOOST_CHECK_EQUAL(boost::math::policies::raise_evaluation_error(func, msg1, T(1.25), ignore_policy), T(1.25));
312 BOOST_CHECK_EQUAL(boost::math::policies::raise_indeterminate_result_error(func, 0, T(0.0), T(12.34), ignore_policy), T(12.34));
313
314 // Test with errno_on_error
315 errno = 0;
316 BOOST_CHECK((boost::math::isnan)(boost::math::policies::raise_domain_error(func, msg1, T(0.0), errno_policy)) || !std::numeric_limits<T>::has_quiet_NaN);
317 BOOST_CHECK(errno == EDOM);
318 errno = 0;
319 BOOST_CHECK((boost::math::isnan)(boost::math::policies::raise_pole_error(func, msg1, T(0.0), errno_policy)) || !std::numeric_limits<T>::has_quiet_NaN);
320 BOOST_CHECK(errno == EDOM);
321 errno = 0;
322 BOOST_CHECK_EQUAL(boost::math::policies::raise_evaluation_error(func, msg1, T(1.25), errno_policy), T(1.25));
323 BOOST_CHECK(errno == EDOM);
324 errno = 0;
325 BOOST_CHECK(boost::math::policies::raise_indeterminate_result_error(func, 0, T(0.0), T(12.34), errno_policy) == T(12.34));
326 BOOST_CHECK_EQUAL(errno, EDOM);
327 }
328
329 BOOST_AUTO_TEST_CASE( test_main )
330 {
331 // Test error handling.
332 // (Parameter value, arbitrarily zero, only communicates the floating point type FPT).
333 test_error(0.0F); // Test float.
334 test_error(0.0); // Test double.
335 test_error(0.0L); // Test long double.
336 test_error(boost::math::concepts::real_concept(0.0L)); // Test concepts.
337
338 // try complex numbers too:
339 test_complex_error(std::complex<float>(0));
340 test_complex_error(std::complex<double>(0));
341 test_complex_error(std::complex<long double>(0));
342
343 test_polynomial_error(boost::math::tools::polynomial<float>());
344
345 } // BOOST_AUTO_TEST_CASE( test_main )
346
347 /*
348
349 Autorun "i:\boost-06-05-03-1300\libs\math\test\Math_test\debug\test_error_handling.exe"
350 Running 1 test case...
351 Error in function boost::math::test_function<float>(float, float, float): Error while handling value 0
352 Error in function boost::math::test_function<float>(float, float, float): Domain Error evaluating function at 0
353 Error in function boost::math::test_function<float>(float, float, float): Error while handling value 0
354 Error in function boost::math::test_function<float>(float, float, float): Evaluation of function at pole 0
355 Error in function boost::math::test_function<float>(float, float, float): Error message goes here...
356 Error in function boost::math::test_function<float>(float, float, float): Overflow Error
357 Error in function boost::math::test_function<float>(float, float, float): Error message goes here...
358 Error in function boost::math::test_function<float>(float, float, float): Underflow Error
359 Error in function boost::math::test_function<float>(float, float, float): Error message goes here...
360 Error in function boost::math::test_function<float>(float, float, float): Denorm Error
361 Error in function boost::math::test_function<float>(float, float, float): Error while handling value 1.25
362 Error in function boost::math::test_function<float>(float, float, float): Internal Evaluation Error, best value so far was 1.25
363 Error in function boost::math::test_function<double>(double, double, double): Error while handling value 0
364 Error in function boost::math::test_function<double>(double, double, double): Domain Error evaluating function at 0
365 Error in function boost::math::test_function<double>(double, double, double): Error while handling value 0
366 Error in function boost::math::test_function<double>(double, double, double): Evaluation of function at pole 0
367 Error in function boost::math::test_function<double>(double, double, double): Error message goes here...
368 Error in function boost::math::test_function<double>(double, double, double): Overflow Error
369 Error in function boost::math::test_function<double>(double, double, double): Error message goes here...
370 Error in function boost::math::test_function<double>(double, double, double): Underflow Error
371 Error in function boost::math::test_function<double>(double, double, double): Error message goes here...
372 Error in function boost::math::test_function<double>(double, double, double): Denorm Error
373 Error in function boost::math::test_function<double>(double, double, double): Error while handling value 1.25
374 Error in function boost::math::test_function<double>(double, double, double): Internal Evaluation Error, best value so far was 1.25
375 Error in function boost::math::test_function<long double>(long double, long double, long double): Error while handling value 0
376 Error in function boost::math::test_function<long double>(long double, long double, long double): Domain Error evaluating function at 0
377 Error in function boost::math::test_function<long double>(long double, long double, long double): Error while handling value 0
378 Error in function boost::math::test_function<long double>(long double, long double, long double): Evaluation of function at pole 0
379 Error in function boost::math::test_function<long double>(long double, long double, long double): Error message goes here...
380 Error in function boost::math::test_function<long double>(long double, long double, long double): Overflow Error
381 Error in function boost::math::test_function<long double>(long double, long double, long double): Error message goes here...
382 Error in function boost::math::test_function<long double>(long double, long double, long double): Underflow Error
383 Error in function boost::math::test_function<long double>(long double, long double, long double): Error message goes here...
384 Error in function boost::math::test_function<long double>(long double, long double, long double): Denorm Error
385 Error in function boost::math::test_function<long double>(long double, long double, long double): Error while handling value 1.25
386 Error in function boost::math::test_function<long double>(long double, long double, long double): Internal Evaluation Error, best value so far was 1.25
387 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Error while handling value 0
388 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Domain Error evaluating function at 0
389 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Error while handling value 0
390 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Evaluation of function at pole 0
391 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Error message goes here...
392 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Overflow Error
393 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Error message goes here...
394 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Underflow Error
395 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Error message goes here...
396 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Denorm Error
397 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Error while handling value 1.25
398 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Internal Evaluation Error, best value so far was 1.25
399 *** No errors detected
400
401 VS 2010
402 ------ Rebuild All started: Project: test_error_handling, Configuration: Release Win32 ------
403 test_error_handling.cpp
404 Generating code
405 Finished generating code
406 test_error_handling.vcxproj -> J:\Cpp\MathToolkit\test\Math_test\Release\test_error_handling.exe
407 Running 1 test case...
408 Error in function boost::math::test_function<float>(float, float, float): Error while handling value 0
409 Error in function boost::math::test_function<float>(float, float, float): Domain Error evaluating function at 0
410 Error in function boost::math::test_function<float>(float, float, float): Error while handling value 0
411 Error in function boost::math::test_function<float>(float, float, float): Evaluation of function at pole 0
412 Error in function boost::math::test_function<float>(float, float, float): Error message goes here...
413 Error in function boost::math::test_function<float>(float, float, float): Overflow Error
414 Error in function boost::math::test_function<float>(float, float, float): Error message goes here...
415 Error in function boost::math::test_function<float>(float, float, float): Underflow Error
416 Error in function boost::math::test_function<float>(float, float, float): Error message goes here...
417 Error in function boost::math::test_function<float>(float, float, float): Denorm Error
418 Error in function boost::math::test_function<float>(float, float, float): Error while handling value 1.25
419 Error in function boost::math::test_function<float>(float, float, float): Internal Evaluation Error, best value so far was 1.25
420 Error in function boost::math::test_function<float>(float, float, float): Error while handling value 1.25
421 Error in function boost::math::test_function<float>(float, float, float): Indeterminate result with value 1.25
422 Error in function boost::math::test_function<double>(double, double, double): Error while handling value 0
423 Error in function boost::math::test_function<double>(double, double, double): Domain Error evaluating function at 0
424 Error in function boost::math::test_function<double>(double, double, double): Error while handling value 0
425 Error in function boost::math::test_function<double>(double, double, double): Evaluation of function at pole 0
426 Error in function boost::math::test_function<double>(double, double, double): Error message goes here...
427 Error in function boost::math::test_function<double>(double, double, double): Overflow Error
428 Error in function boost::math::test_function<double>(double, double, double): Error message goes here...
429 Error in function boost::math::test_function<double>(double, double, double): Underflow Error
430 Error in function boost::math::test_function<double>(double, double, double): Error message goes here...
431 Error in function boost::math::test_function<double>(double, double, double): Denorm Error
432 Error in function boost::math::test_function<double>(double, double, double): Error while handling value 1.25
433 Error in function boost::math::test_function<double>(double, double, double): Internal Evaluation Error, best value so far was 1.25
434 Error in function boost::math::test_function<double>(double, double, double): Error while handling value 1.25
435 Error in function boost::math::test_function<double>(double, double, double): Indeterminate result with value 1.25
436 Error in function boost::math::test_function<long double>(long double, long double, long double): Error while handling value 0
437 Error in function boost::math::test_function<long double>(long double, long double, long double): Domain Error evaluating function at 0
438 Error in function boost::math::test_function<long double>(long double, long double, long double): Error while handling value 0
439 Error in function boost::math::test_function<long double>(long double, long double, long double): Evaluation of function at pole 0
440 Error in function boost::math::test_function<long double>(long double, long double, long double): Error message goes here...
441 Error in function boost::math::test_function<long double>(long double, long double, long double): Overflow Error
442 Error in function boost::math::test_function<long double>(long double, long double, long double): Error message goes here...
443 Error in function boost::math::test_function<long double>(long double, long double, long double): Underflow Error
444 Error in function boost::math::test_function<long double>(long double, long double, long double): Error message goes here...
445 Error in function boost::math::test_function<long double>(long double, long double, long double): Denorm Error
446 Error in function boost::math::test_function<long double>(long double, long double, long double): Error while handling value 1.25
447 Error in function boost::math::test_function<long double>(long double, long double, long double): Internal Evaluation Error, best value so far was 1.25
448 Error in function boost::math::test_function<long double>(long double, long double, long double): Error while handling value 1.25
449 Error in function boost::math::test_function<long double>(long double, long double, long double): Indeterminate result with value 1.25
450 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Error while handling value 0
451 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Domain Error evaluating function at 0
452 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Error while handling value 0
453 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Evaluation of function at pole 0
454 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Error message goes here...
455 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Overflow Error
456 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Error message goes here...
457 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Underflow Error
458 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Error message goes here...
459 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Denorm Error
460 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Error while handling value 1.25
461 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Internal Evaluation Error, best value so far was 1.25
462 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Error while handling value 1.25
463
464 *** No errors detected
465 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Indeterminate result with value 1.25
466 ========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
467
468
469 */
470