16
16
#include < boost/math/distributions/detail/hypergeometric_cdf.hpp>
17
17
#include < boost/math/distributions/detail/hypergeometric_quantile.hpp>
18
18
#include < boost/math/special_functions/fpclassify.hpp>
19
+ #include < cstdint>
19
20
20
21
namespace boost { namespace math {
21
22
@@ -26,25 +27,25 @@ namespace boost { namespace math {
26
27
typedef RealType value_type;
27
28
typedef Policy policy_type;
28
29
29
- hypergeometric_distribution (unsigned r, unsigned n, unsigned N) // Constructor. r=defective/failures/success, n=trials/draws, N=total population.
30
+ hypergeometric_distribution (std:: uint64_t r, std:: uint64_t n, std:: uint64_t N) // Constructor. r=defective/failures/success, n=trials/draws, N=total population.
30
31
: m_n(n), m_N(N), m_r(r)
31
32
{
32
33
static const char * function = " boost::math::hypergeometric_distribution<%1%>::hypergeometric_distribution" ;
33
34
RealType ret;
34
35
check_params (function, &ret);
35
36
}
36
37
// Accessor functions.
37
- unsigned total ()const
38
+ std:: uint64_t total () const
38
39
{
39
40
return m_N;
40
41
}
41
42
42
- unsigned defective ()const // successes/failures/events
43
+ std:: uint64_t defective () const // successes/failures/events
43
44
{
44
45
return m_r;
45
46
}
46
47
47
- unsigned sample_count ()const
48
+ std:: uint64_t sample_count ()const
48
49
{
49
50
return m_n;
50
51
}
@@ -65,9 +66,9 @@ namespace boost { namespace math {
65
66
}
66
67
return true ;
67
68
}
68
- bool check_x (unsigned x, const char * function, RealType* result)const
69
+ bool check_x (std:: uint64_t x, const char * function, RealType* result)const
69
70
{
70
- if (x < static_cast <unsigned >((std::max)(0 , static_cast <int >(m_n + m_r) - static_cast <int >(m_N))))
71
+ if (x < static_cast <std:: uint64_t >((std::max)(INT64_C ( 0 ) , static_cast <std:: int64_t >(m_n + m_r) - static_cast <std:: int64_t >(m_N))))
71
72
{
72
73
*result = boost::math::policies::raise_domain_error<RealType>(
73
74
function, " Random variable out of range: must be > 0 and > m + r - N but got %1%" , static_cast <RealType>(x), Policy ());
@@ -84,40 +85,40 @@ namespace boost { namespace math {
84
85
85
86
private:
86
87
// Data members:
87
- unsigned m_n; // number of items picked or drawn.
88
- unsigned m_N; // number of "total" items.
89
- unsigned m_r; // number of "defective/successes/failures/events items.
88
+ std:: uint64_t m_n; // number of items picked or drawn.
89
+ std:: uint64_t m_N; // number of "total" items.
90
+ std:: uint64_t m_r; // number of "defective/successes/failures/events items.
90
91
91
92
}; // class hypergeometric_distribution
92
93
93
94
typedef hypergeometric_distribution<double > hypergeometric;
94
95
95
96
template <class RealType , class Policy >
96
- inline const std::pair<unsigned , unsigned > range (const hypergeometric_distribution<RealType, Policy>& dist)
97
+ inline const std::pair<std:: uint64_t , std:: uint64_t > range (const hypergeometric_distribution<RealType, Policy>& dist)
97
98
{ // Range of permissible values for random variable x.
98
99
#ifdef _MSC_VER
99
100
# pragma warning(push)
100
101
# pragma warning(disable:4267)
101
102
#endif
102
- unsigned r = dist.defective ();
103
- unsigned n = dist.sample_count ();
104
- unsigned N = dist.total ();
105
- unsigned l = static_cast <unsigned >((std::max)(0 , static_cast <int >(n + r) - static_cast <int >(N)));
106
- unsigned u = (std::min)(r, n);
107
- return std::pair< unsigned , unsigned > (l, u);
103
+ const auto r = dist.defective ();
104
+ const auto n = dist.sample_count ();
105
+ const auto N = dist.total ();
106
+ const auto l = static_cast <std:: uint64_t >((std::max)(INT64_C ( 0 ) , static_cast <std:: int64_t >(n + r) - static_cast <std:: int64_t >(N)));
107
+ const auto u = (std::min)(r, n);
108
+ return std::make_pair (l, u);
108
109
#ifdef _MSC_VER
109
110
# pragma warning(pop)
110
111
#endif
111
112
}
112
113
113
114
template <class RealType , class Policy >
114
- inline const std::pair<unsigned , unsigned > support (const hypergeometric_distribution<RealType, Policy>& d)
115
+ inline const std::pair<std:: uint64_t , std:: uint64_t > support (const hypergeometric_distribution<RealType, Policy>& d)
115
116
{
116
117
return range (d);
117
118
}
118
119
119
120
template <class RealType , class Policy >
120
- inline RealType pdf (const hypergeometric_distribution<RealType, Policy>& dist, const unsigned & x)
121
+ inline RealType pdf (const hypergeometric_distribution<RealType, Policy>& dist, const std:: uint64_t & x)
121
122
{
122
123
static const char * function = " boost::math::pdf(const hypergeometric_distribution<%1%>&, const %1%&)" ;
123
124
RealType result = 0 ;
@@ -136,7 +137,7 @@ namespace boost { namespace math {
136
137
BOOST_MATH_STD_USING
137
138
static const char * function = " boost::math::pdf(const hypergeometric_distribution<%1%>&, const %1%&)" ;
138
139
RealType r = static_cast <RealType>(x);
139
- unsigned u = itrunc ( r, typename policies::normalise<Policy, policies::rounding_error<policies::ignore_error> >::type ());
140
+ auto u = static_cast <std:: uint64_t >( lltrunc ( r, typename policies::normalise<Policy, policies::rounding_error<policies::ignore_error> >::type () ));
140
141
if (u != r)
141
142
{
142
143
return boost::math::policies::raise_domain_error<RealType>(
@@ -146,7 +147,7 @@ namespace boost { namespace math {
146
147
}
147
148
148
149
template <class RealType , class Policy >
149
- inline RealType cdf (const hypergeometric_distribution<RealType, Policy>& dist, const unsigned & x)
150
+ inline RealType cdf (const hypergeometric_distribution<RealType, Policy>& dist, const std:: uint64_t & x)
150
151
{
151
152
static const char * function = " boost::math::cdf(const hypergeometric_distribution<%1%>&, const %1%&)" ;
152
153
RealType result = 0 ;
@@ -165,7 +166,7 @@ namespace boost { namespace math {
165
166
BOOST_MATH_STD_USING
166
167
static const char * function = " boost::math::cdf(const hypergeometric_distribution<%1%>&, const %1%&)" ;
167
168
RealType r = static_cast <RealType>(x);
168
- unsigned u = itrunc ( r, typename policies::normalise<Policy, policies::rounding_error<policies::ignore_error> >::type ());
169
+ auto u = static_cast <std:: uint64_t >( lltrunc ( r, typename policies::normalise<Policy, policies::rounding_error<policies::ignore_error> >::type () ));
169
170
if (u != r)
170
171
{
171
172
return boost::math::policies::raise_domain_error<RealType>(
@@ -175,7 +176,7 @@ namespace boost { namespace math {
175
176
}
176
177
177
178
template <class RealType , class Policy >
178
- inline RealType cdf (const complemented2_type<hypergeometric_distribution<RealType, Policy>, unsigned >& c)
179
+ inline RealType cdf (const complemented2_type<hypergeometric_distribution<RealType, Policy>, std:: uint64_t >& c)
179
180
{
180
181
static const char * function = " boost::math::cdf(const hypergeometric_distribution<%1%>&, const %1%&)" ;
181
182
RealType result = 0 ;
@@ -194,7 +195,7 @@ namespace boost { namespace math {
194
195
BOOST_MATH_STD_USING
195
196
static const char * function = " boost::math::cdf(const hypergeometric_distribution<%1%>&, const %1%&)" ;
196
197
RealType r = static_cast <RealType>(c.param );
197
- unsigned u = itrunc ( r, typename policies::normalise<Policy, policies::rounding_error<policies::ignore_error> >::type ());
198
+ auto u = static_cast <std:: uint64_t >( lltrunc ( r, typename policies::normalise<Policy, policies::rounding_error<policies::ignore_error> >::type () ));
198
199
if (u != r)
199
200
{
200
201
return boost::math::policies::raise_domain_error<RealType>(
@@ -208,11 +209,14 @@ namespace boost { namespace math {
208
209
{
209
210
BOOST_MATH_STD_USING // for ADL of std functions
210
211
211
- // Checking function argument
212
- RealType result = 0 ;
212
+ // Checking function argument
213
+ RealType result = 0 ;
213
214
const char * function = " boost::math::quantile(const hypergeometric_distribution<%1%>&, %1%)" ;
214
- if (false == dist.check_params (function, &result)) return result;
215
- if (false == detail::check_probability (function, p, &result, Policy ())) return result;
215
+ if (false == dist.check_params (function, &result))
216
+ return result;
217
+
218
+ if (false == detail::check_probability (function, p, &result, Policy ()))
219
+ return result;
216
220
217
221
return static_cast <RealType>(detail::hypergeometric_quantile (p, RealType (1 - p), dist.defective (), dist.sample_count (), dist.total (), Policy ()));
218
222
} // quantile
@@ -225,8 +229,10 @@ namespace boost { namespace math {
225
229
// Checking function argument
226
230
RealType result = 0 ;
227
231
const char * function = " quantile(const complemented2_type<hypergeometric_distribution<%1%>, %1%>&)" ;
228
- if (false == c.dist .check_params (function, &result)) return result;
229
- if (false == detail::check_probability (function, c.param , &result, Policy ())) return result;
232
+ if (false == c.dist .check_params (function, &result))
233
+ return result;
234
+ if (false == detail::check_probability (function, c.param , &result, Policy ()))
235
+ return result;
230
236
231
237
return static_cast <RealType>(detail::hypergeometric_quantile (RealType (1 - c.param ), c.param , c.dist .defective (), c.dist .sample_count (), c.dist .total (), Policy ()));
232
238
} // quantile
0 commit comments