Stan  1.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
boost_error_handling.hpp
Go to the documentation of this file.
1 #ifndef __STAN__MATH__BOOST_ERROR_HANDLING_HPP__
2 #define __STAN__MATH__BOOST_ERROR_HANDLING_HPP__
3 
4 #include <boost/math/policies/policy.hpp>
5 #include <boost/math/policies/error_handling.hpp>
6 #include <boost/math/distributions/detail/common_error_handling.hpp>
7 
8 namespace stan {
9  namespace math {
10  namespace policies {
11  namespace detail {
12  using boost::math::policies::detail::raise_error;
13  template <class T_result, class T_val>
14  inline T_result raise_domain_error(const char* function,
15  const char* message,
16  const T_val& val,
17  const ::boost::math::policies::domain_error< ::boost::math::policies::throw_on_error>&) {
18  raise_error<std::domain_error, T_val>(function, message, val);
19  // we never get here:
20  return std::numeric_limits<T_result>::quiet_NaN();
21  }
22 
23  template <class T_result, class T_val>
24  inline T_result raise_domain_error(const char* ,
25  const char* ,
26  const T_val& ,
27  const ::boost::math::policies::domain_error< ::boost::math::policies::ignore_error>&) {
28  // This may or may not do the right thing, but the user asked for the error
29  // to be ignored so here we go anyway:
30  return std::numeric_limits<T_result>::quiet_NaN();
31  }
32 
33  template <class T_result, class T_val>
34  inline T_result raise_domain_error(const char* ,
35  const char* ,
36  const T_val& ,
37  const ::boost::math::policies::domain_error< ::boost::math::policies::errno_on_error>&) {
38  errno = EDOM;
39  // This may or may not do the right thing, but the user asked for the error
40  // to be silent so here we go anyway:
41  return std::numeric_limits<T_result>::quiet_NaN();
42  }
43 
44  template <class T_result, class T_val>
45  inline T_result raise_domain_error(const char* function,
46  const char* message,
47  const T_val& val,
48  const ::boost::math::policies::domain_error< ::boost::math::policies::user_error>&) {
49  return user_domain_error(function, message, val);
50  }
51 
52  }
53 
54  template <class T_result, class T_val, class Policy>
55  inline T_result raise_domain_error(const char* function,
56  const char* message,
57  const T_val& val,
58  const Policy&) {
59  typedef typename Policy::domain_error_type policy_type;
60  return detail::raise_domain_error<T_result,T_val>(function,
61  message ? message : "Domain Error evaluating function at %1%",
62  val,
63  policy_type());
64 
65  }
66  }
67  }
68 
69 }
70 
71 // FIXME: remove when BOOST fixes isfinite(). See ticket #6517. (Boost 1.48.0)
72 // https://svn.boost.org/trac/boost/ticket/6517
73 namespace boost {
74 
75  namespace math {
76 
86  template <>
87  inline
88  bool isfinite(short n) {
89  return true;
90  }
100  template <>
101  inline
102  bool isinf(short n) {
103  return false;
104  }
113  template <>
114  inline
115  bool isnan(short n) {
116  return false;
117  }
127  template <>
128  inline
129  bool isnormal(short n) {
130  return true;
131  }
132 
133 
143  template <>
144  inline
145  bool isfinite(unsigned short n) {
146  return true;
147  }
157  template <>
158  inline
159  bool isinf(unsigned short n) {
160  return false;
161  }
170  template <>
171  inline
172  bool isnan(unsigned short n) {
173  return false;
174  }
184  template <>
185  inline
186  bool isnormal(unsigned short n) {
187  return true;
188  }
189 
190 
200  template <>
201  inline
202  bool isfinite(int n) {
203  return true;
204  }
214  template <>
215  inline
216  bool isinf(int n) {
217  return false;
218  }
227  template <>
228  inline
229  bool isnan(int n) {
230  return false;
231  }
241  template <>
242  inline
243  bool isnormal(int n) {
244  return true;
245  }
246 
247 
257  template <>
258  inline
259  bool isfinite(unsigned int n) {
260  return true;
261  }
271  template <>
272  inline
273  bool isinf(unsigned int n) {
274  return false;
275  }
284  template <>
285  inline
286  bool isnan(unsigned int n) {
287  return false;
288  }
298  template <>
299  inline
300  bool isnormal(unsigned int n) {
301  return true;
302  }
303 
304 
314  template <>
315  inline
316  bool isfinite(long n) {
317  return true;
318  }
328  template <>
329  inline
330  bool isinf(long n) {
331  return false;
332  }
341  template <>
342  inline
343  bool isnan(long n) {
344  return false;
345  }
355  template <>
356  inline
357  bool isnormal(long n) {
358  return true;
359  }
360 
361 
371  template <>
372  inline
373  bool isfinite(unsigned long n) {
374  return true;
375  }
385  template <>
386  inline
387  bool isinf(unsigned long n) {
388  return false;
389  }
398  template <>
399  inline
400  bool isnan(unsigned long n) {
401  return false;
402  }
412  template <>
413  inline
414  bool isnormal(unsigned long n) {
415  return true;
416  }
417 
418 
428  template <>
429  inline
430  bool isfinite(long long n) {
431  return true;
432  }
442  template <>
443  inline
444  bool isinf(long long n) {
445  return false;
446  }
455  template <>
456  inline
457  bool isnan(long long n) {
458  return false;
459  }
469  template <>
470  inline
471  bool isnormal(long long n) {
472  return true;
473  }
474 
475 
485  template <>
486  inline
487  bool isfinite(unsigned long long n) {
488  return true;
489  }
499  template <>
500  inline
501  bool isinf(unsigned long long n) {
502  return false;
503  }
512  template <>
513  inline
514  bool isnan(unsigned long long n) {
515  return false;
516  }
526  template <>
527  inline
528  bool isnormal(unsigned long long n) {
529  return true;
530  }
531 
532  }
533 
534 }
535 
536 #endif

     [ Stan Home Page ] © 2011–2012, Stan Development Team.