policy_ref_snip11.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. // Note that this file contains quickbook mark-up as well as code
  7. // and comments, don't change any of the special comment mark-ups!
  8. #include <iostream>
  9. using std::cout; using std::endl;
  10. // Setting (approximate) precision 25 bits in a single function call using make_policy.
  11. //[policy_ref_snip11
  12. #include <boost/math/distributions/normal.hpp>
  13. using boost::math::normal_distribution;
  14. using namespace boost::math::policies;
  15. const int bits = 25; // approximate precision.
  16. double q = quantile(
  17. normal_distribution<double, policy<digits2<bits> > >(),
  18. 0.05); // 5% quantile.
  19. //] //[/policy_ref_snip11]
  20. int main()
  21. {
  22. std::streamsize p = 2 + (bits * 30103UL) / 100000UL;
  23. // Approximate number of significant decimal digits for 25 bits.
  24. cout.precision(p);
  25. cout << bits << " binary bits is approoximately equivalent to " << p << " decimal digits " << endl;
  26. cout << "quantile(normal_distribution<double, policy<digits2<25> > >(), 0.05 = "
  27. << q << endl; // -1.64485
  28. }
  29. /*
  30. Output:
  31. 25 binary bits is approoximately equivalent to 9 decimal digits
  32. quantile(normal_distribution<double, policy<digits2<25> > >(), 0.05 = -1.64485363
  33. */