]> git.donarmstrong.com Git - rsem.git/blob - boost/math/distributions/detail/common_error_handling.hpp
Added posterior standard deviation of counts as output if either '--calc-pme' or...
[rsem.git] / boost / math / distributions / detail / common_error_handling.hpp
1 // Copyright John Maddock 2006, 2007.
2 // Copyright Paul A. Bristow 2006, 2007.
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 #ifndef BOOST_MATH_DISTRIBUTIONS_COMMON_ERROR_HANDLING_HPP
10 #define BOOST_MATH_DISTRIBUTIONS_COMMON_ERROR_HANDLING_HPP
11
12 #include <boost/math/policies/error_handling.hpp>
13 #include <boost/math/special_functions/fpclassify.hpp>
14 // using boost::math::isfinite;
15
16 namespace boost{ namespace math{ namespace detail
17 {
18
19 template <class RealType, class Policy>
20 inline bool check_probability(const char* function, RealType const& prob, RealType* result, const Policy& pol)
21 {
22    if((prob < 0) || (prob > 1) || !(boost::math::isfinite)(prob))
23    {
24       *result = policies::raise_domain_error<RealType>(
25          function,
26          "Probability argument is %1%, but must be >= 0 and <= 1 !", prob, pol);
27       return false;
28    }
29    return true;
30 }
31
32 template <class RealType, class Policy>
33 inline bool check_df(const char* function, RealType const& df, RealType* result, const Policy& pol)
34 {
35    if((df <= 0) || !(boost::math::isfinite)(df))
36    {
37       *result = policies::raise_domain_error<RealType>(
38          function,
39          "Degrees of freedom argument is %1%, but must be > 0 !", df, pol);
40       return false;
41    }
42    return true;
43 }
44
45 template <class RealType, class Policy>
46 inline bool check_scale(
47       const char* function,
48       RealType scale,
49       RealType* result,
50       const Policy& pol)
51 {
52    if((scale <= 0) || !(boost::math::isfinite)(scale))
53    { // Assume scale == 0 is NOT valid for any distribution.
54       *result = policies::raise_domain_error<RealType>(
55          function,
56          "Scale parameter is %1%, but must be > 0 !", scale, pol);
57       return false;
58    }
59    return true;
60 }
61
62 template <class RealType, class Policy>
63 inline bool check_location(
64       const char* function,
65       RealType location,
66       RealType* result,
67       const Policy& pol)
68 {
69    if(!(boost::math::isfinite)(location))
70    {
71       *result = policies::raise_domain_error<RealType>(
72          function,
73          "Location parameter is %1%, but must be finite!", location, pol);
74       return false;
75    }
76    return true;
77 }
78
79 template <class RealType, class Policy>
80 inline bool check_x(
81       const char* function,
82       RealType x,
83       RealType* result,
84       const Policy& pol)
85 {
86    if(!(boost::math::isfinite)(x))
87    {
88       *result = policies::raise_domain_error<RealType>(
89          function,
90          "Random variate x is %1%, but must be finite!", x, pol);
91       return false;
92    }
93    return true;
94    // Note that this test catches both infinity and NaN.
95    // Some special cases permit x to be infinite, so these must be tested 1st,
96    // leaving this test to catch any NaNs.  see Normal and cauchy for example.
97 }
98
99 template <class RealType, class Policy>
100 inline bool check_positive_x(
101       const char* function,
102       RealType x,
103       RealType* result,
104       const Policy& pol)
105 {
106    if(!(boost::math::isfinite)(x) || (x < 0))
107    {
108       *result = policies::raise_domain_error<RealType>(
109          function,
110          "Random variate x is %1%, but must be finite and >= 0!", x, pol);
111       return false;
112    }
113    return true;
114    // Note that this test catches both infinity and NaN.
115    // Some special cases permit x to be infinite, so these must be tested 1st,
116    // leaving this test to catch any NaNs.  see Normal and cauchy for example.
117 }
118
119 template <class RealType, class Policy>
120 inline bool check_non_centrality(
121       const char* function,
122       RealType ncp,
123       RealType* result,
124       const Policy& pol)
125 {
126    if((ncp < 0) || !(boost::math::isfinite)(ncp))
127    { // Assume scale == 0 is NOT valid for any distribution.
128       *result = policies::raise_domain_error<RealType>(
129          function,
130          "Non centrality parameter is %1%, but must be > 0 !", ncp, pol);
131       return false;
132    }
133    return true;
134 }
135
136 template <class RealType, class Policy>
137 inline bool check_finite(
138       const char* function,
139       RealType x,
140       RealType* result,
141       const Policy& pol)
142 {
143    if(!(boost::math::isfinite)(x))
144    { // Assume scale == 0 is NOT valid for any distribution.
145       *result = policies::raise_domain_error<RealType>(
146          function,
147          "Parameter is %1%, but must be finite !", x, pol);
148       return false;
149    }
150    return true;
151 }
152
153 } // namespace detail
154 } // namespace math
155 } // namespace boost
156
157 #endif // BOOST_MATH_DISTRIBUTIONS_COMMON_ERROR_HANDLING_HPP