]>
git.proxmox.com Git - ceph.git/blob - 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)
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!
11 using std::cout
; using std::endl
;
12 #include <cerrno> // for ::errno
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'.
22 { // anonymous or unnnamed (rather than named as in policy_eg_6.cpp).
24 using namespace boost::math::policies
;
25 // using boost::math::policies::errno_on_error; // etc.
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
>
35 BOOST_MATH_DECLARE_DISTRIBUTIONS(double, my_policy
)
37 } // close namespace my_namespace
41 // Construct distribution with something we know will overflow.
42 normal
norm(10, 2); // using 'anonymous-namespace'::normal
44 cout
<< "Result of quantile(norm, 0) is: "
45 << quantile(norm
, 0) << endl
;
46 cout
<< "errno = " << errno
<< endl
;
48 cout
<< "Result of quantile(norm, 1) is: "
49 << quantile(norm
, 1) << endl
;
50 cout
<< "errno = " << errno
<< endl
;
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
;
66 Result of quantile(norm, 0) is: -1.#INF
68 Result of quantile(norm, 1) is: 1.#INF
70 Result of quantile(binom, 0.05) is: 1
71 Result of quantile(complement(binom, 0.05)) is: 8