policy_ref_snip9.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  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. //[policy_ref_snip9
  11. #include <boost/math/special_functions/gamma.hpp>
  12. using boost::math::tgamma;
  13. using boost::math::policies::policy;
  14. using boost::math::policies::digits10;
  15. typedef policy<digits10<5> > my_pol_5; // Define a new, non-default, policy
  16. // to calculate tgamma to accuracy of approximately 5 decimal digits.
  17. //]
  18. int main()
  19. {
  20. cout.precision(5); // To only show 5 (hopefully) accurate decimal digits.
  21. double t = tgamma(12, my_pol_5()); // Apply the 5 decimal digits accuracy policy to use of tgamma.
  22. cout << "tgamma(12, my_pol_5() = " << t << endl;
  23. }
  24. /*
  25. Output:
  26. tgamma(12, my_pol_5() = 3.9917e+007
  27. */