policy_eg_2.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. #include <iostream>
  7. using std::cout; using std::endl;
  8. #include <cerrno> // for ::errno
  9. //[policy_eg_2
  10. #include <boost/math/special_functions/gamma.hpp>
  11. using boost::math::tgamma;
  12. int main()
  13. {
  14. // using namespace boost::math::policies; // or
  15. using boost::math::policies::errno_on_error;
  16. using boost::math::policies::make_policy;
  17. using boost::math::policies::pole_error;
  18. using boost::math::policies::domain_error;
  19. using boost::math::policies::overflow_error;
  20. using boost::math::policies::evaluation_error;
  21. errno = 0;
  22. std::cout << "Result of tgamma(30000) is: "
  23. << boost::math::tgamma(
  24. 30000,
  25. make_policy(
  26. domain_error<errno_on_error>(),
  27. pole_error<errno_on_error>(),
  28. overflow_error<errno_on_error>(),
  29. evaluation_error<errno_on_error>()
  30. )
  31. ) << std::endl;
  32. // Check errno was set:
  33. std::cout << "errno = " << errno << std::endl;
  34. // and again with evaluation at a pole:
  35. std::cout << "Result of tgamma(-10) is: "
  36. << boost::math::tgamma(
  37. -10,
  38. make_policy(
  39. domain_error<errno_on_error>(),
  40. pole_error<errno_on_error>(),
  41. overflow_error<errno_on_error>(),
  42. evaluation_error<errno_on_error>()
  43. )
  44. ) << std::endl;
  45. // Check errno was set:
  46. std::cout << "errno = " << errno << std::endl;
  47. }
  48. //] //[/policy_eg_2]
  49. /*
  50. Output:
  51. Result of tgamma(30000) is: 1.#INF
  52. errno = 34
  53. Result of tgamma(-10) is: 1.#QNAN
  54. errno = 33
  55. */