1 // Copyright Paul A. Bristow 2006-7.
2 // Copyright John Maddock 2006-7.
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)
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
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.
16 struct user_defined_error
{};
18 namespace boost
{ namespace math
{ namespace policies
{
20 #ifndef BOOST_NO_EXCEPTIONS
23 T
user_domain_error(const char* , const char* , const T
& )
25 throw user_defined_error();
29 T
user_pole_error(const char* , const char* , const T
& )
31 throw user_defined_error();
35 T
user_overflow_error(const char* , const char* , const T
& )
37 throw user_defined_error();
41 T
user_underflow_error(const char* , const char* , const T
& )
43 throw user_defined_error();
47 T
user_denorm_error(const char* , const char* , const T
& )
49 throw user_defined_error();
53 T
user_evaluation_error(const char* , const char* , const T
& )
55 throw user_defined_error();
59 T
user_indeterminate_result_error(const char* , const char* , const T
& )
61 throw user_defined_error();
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
77 // Define some policies:
79 using namespace boost::math::policies
;
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
;
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
;
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
;
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
;
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)); }
119 std::string
format_message_string(const char* str
)
121 std::string type_name
= boost::math::policies::detail::name_of
<T
>();
122 std::string
result(str
);
123 if(type_name
!= "float")
125 std::string::size_type pos
= 0;
126 while((pos
= result
.find("float", pos
)) != std::string::npos
)
128 result
.replace(pos
, 5, type_name
);
129 pos
+= type_name
.size();
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...";
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"));
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
);
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));
180 // Test with errno_on_error
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
);
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
);
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
);
191 BOOST_CHECK_EQUAL(boost::math::policies::raise_underflow_error
<T
>(func
, msg2
, errno_policy
), T(0));
192 BOOST_CHECK_EQUAL(errno
, ERANGE
);
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
);
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
);
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
);
205 void test_complex_error(T
)
208 // Error handling that can be applied to non-scalar types such as std::complex
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...";
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)"));
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
);
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));
252 // Test with errno_on_error
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
);
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
);
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);
263 BOOST_CHECK_EQUAL(boost::math::policies::raise_underflow_error
<T
>(func
, msg2
, errno_policy
), T(0));
264 BOOST_CHECK_EQUAL(errno
, ERANGE
);
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
);
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
);
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
);
277 void test_polynomial_error(T
)
280 // Error handling that can be applied to non-scalar types such as std::complex
282 const char* func
= "boost::math::test_function<%1%>(%1%, %1%, %1%)";
283 const char* msg1
= "Error while handling value %1%";
285 static const typename
T::value_type data
[] = { 1, 2, 3 };
286 static const T
val(data
, 2);
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 }"));
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
);
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));
314 // Test with errno_on_error
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
);
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
);
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
);
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
);
329 BOOST_AUTO_TEST_CASE( test_main
)
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.
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));
343 test_polynomial_error(boost::math::tools::polynomial
<float>());
345 } // BOOST_AUTO_TEST_CASE( test_main )
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
402 ------ Rebuild All started: Project: test_error_handling, Configuration: Release Win32 ------
403 test_error_handling.cpp
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
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 ==========