policy_eg_3.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright John Maddock 2007.
  2. // Copyright Paul A. Bristow 2007, 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. #ifdef _MSC_VER
  7. # pragma warning (disable : 4305) // 'initializing' : truncation from 'long double' to 'const eval_type'
  8. # pragma warning (disable : 4244) // conversion from 'long double' to 'const eval_type'
  9. #endif
  10. #include <iostream>
  11. using std::cout; using std::endl;
  12. //[policy_eg_3
  13. #include <boost/math/distributions/binomial.hpp>
  14. using boost::math::binomial_distribution;
  15. // Begin by defining a policy type, that gives the behaviour we want:
  16. //using namespace boost::math::policies; or explicitly
  17. using boost::math::policies::policy;
  18. using boost::math::policies::promote_float;
  19. using boost::math::policies::discrete_quantile;
  20. using boost::math::policies::integer_round_nearest;
  21. typedef policy<
  22. promote_float<false>, // Do not promote to double.
  23. discrete_quantile<integer_round_nearest> // Round result to nearest integer.
  24. > mypolicy;
  25. //
  26. // Then define a new distribution that uses it:
  27. typedef boost::math::binomial_distribution<float, mypolicy> mybinom;
  28. // And now use it to get the quantile:
  29. int main()
  30. {
  31. cout << "quantile(mybinom(200, 0.25), 0.05) is: " <<
  32. quantile(mybinom(200, 0.25), 0.05) << endl;
  33. }
  34. //]
  35. /*
  36. Output:
  37. quantile(mybinom(200, 0.25), 0.05) is: 40
  38. */