]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/math/example/policy_eg_7.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / math / example / policy_eg_7.cpp
1 // Copyright John Maddock 2007.
2 // Copyright Paul A. Bristow 2010
3 // Use, modification and distribution are subject to the
4 // Boost Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6
7 // Note that this file contains quickbook mark-up as well as code
8 // and comments, don't change any of the special comment mark-ups!
9
10 #include <iostream>
11 using std::cout; using std::endl;
12 #include <cerrno> // for ::errno
13
14 //[policy_eg_7
15
16 #include <boost/math/distributions.hpp> // All distributions.
17 // using boost::math::normal; // Would create an ambguity between
18 // boost::math::normal_distribution<RealType> boost::math::normal and
19 // 'anonymous-namespace'::normal'.
20
21 namespace
22 { // anonymous or unnnamed (rather than named as in policy_eg_6.cpp).
23
24 using namespace boost::math::policies;
25 // using boost::math::policies::errno_on_error; // etc.
26 typedef policy<
27 // return infinity and set errno rather than throw:
28 overflow_error<errno_on_error>,
29 // Don't promote double -> long double internally:
30 promote_double<false>,
31 // Return the closest integer result for discrete quantiles:
32 discrete_quantile<integer_round_nearest>
33 > my_policy;
34
35 BOOST_MATH_DECLARE_DISTRIBUTIONS(double, my_policy)
36
37 } // close namespace my_namespace
38
39 int main()
40 {
41 // Construct distribution with something we know will overflow.
42 normal norm(10, 2); // using 'anonymous-namespace'::normal
43 errno = 0;
44 cout << "Result of quantile(norm, 0) is: "
45 << quantile(norm, 0) << endl;
46 cout << "errno = " << errno << endl;
47 errno = 0;
48 cout << "Result of quantile(norm, 1) is: "
49 << quantile(norm, 1) << endl;
50 cout << "errno = " << errno << endl;
51 //
52 // Now try a discrete distribution:
53 binomial binom(20, 0.25);
54 cout << "Result of quantile(binom, 0.05) is: "
55 << quantile(binom, 0.05) << endl;
56 cout << "Result of quantile(complement(binom, 0.05)) is: "
57 << quantile(complement(binom, 0.05)) << endl;
58 }
59
60 //] //[/policy_eg_7]
61
62 /*
63
64 Output:
65
66 Result of quantile(norm, 0) is: -1.#INF
67 errno = 34
68 Result of quantile(norm, 1) is: 1.#INF
69 errno = 34
70 Result of quantile(binom, 0.05) is: 1
71 Result of quantile(complement(binom, 0.05)) is: 8
72
73 */