1 // Copyright John Maddock 2007.
2 // Copyright Paul A. Bristow 2007, 2010.
3
4 // Use, modification and distribution are subject to the
5 // Boost Software License, Version 1.0. (See accompanying file
6 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7
8 #ifdef _MSC_VER
9 # pragma warning (disable : 4305) // 'initializing' : truncation from 'long double' to 'const eval_type'
10 # pragma warning (disable : 4244) // conversion from 'long double' to 'const eval_type'
11 #endif
12
13 #include <iostream>
14 using std::cout; using std::endl;
15
16 //[policy_eg_3
17
18 #include <boost/math/distributions/binomial.hpp>
19 using boost::math::binomial_distribution;
20
21 // Begin by defining a policy type, that gives the behaviour we want:
22
23 //using namespace boost::math::policies; or explicitly
24 using boost::math::policies::policy;
25
26 using boost::math::policies::promote_float;
27 using boost::math::policies::discrete_quantile;
28 using boost::math::policies::integer_round_nearest;
29
30 typedef policy<
31 promote_float<false>, // Do not promote to double.
32 discrete_quantile<integer_round_nearest> // Round result to nearest integer.
33 > mypolicy;
34 //
35 // Then define a new distribution that uses it:
36 typedef boost::math::binomial_distribution<float, mypolicy> mybinom;
37
38 // And now use it to get the quantile:
39
main()40 int main()
41 {
42 cout << "quantile(mybinom(200, 0.25), 0.05) is: " <<
43 quantile(mybinom(200, 0.25), 0.05) << endl;
44 }
45
46 //]
47
48 /*
49
50 Output:
51
52 quantile(mybinom(200, 0.25), 0.05) is: 40
53
54 */
55
56