inverse_gamma_example.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // inverse_gamma_example.cpp
  2. // Copyright Paul A. Bristow 2010.
  3. // Use, modification and distribution are subject to the
  4. // Boost Software License, Version 1.0.
  5. // (See accompanying file LICENSE_1_0.txt
  6. // or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. // Example 1 of using inverse gamma functions.
  8. #include <boost/math/special_functions/gamma.hpp>
  9. using boost::math::gamma_p_inv; // Compute x given a
  10. //using boost::math::gamma_q_inv;
  11. //using boost::math::gamma_p_inva; // Compute a given x
  12. //using boost::math::gamma_q_inva;
  13. #include <iostream>
  14. using std::cout; using std::endl;
  15. #include <iomanip>
  16. using std::setprecision;
  17. #include <cmath>
  18. using std::sqrt;
  19. #include <limits>
  20. int main()
  21. {
  22. cout << "Example 1 using Inverse Gamma function. " << endl;
  23. #ifdef BOOST_NO_CXX11_NUMERIC_LIMITS
  24. int max_digits10 = 2 + (boost::math::policies::digits<double, boost::math::policies::policy<> >() * 30103UL) / 100000UL;
  25. cout << "BOOST_NO_CXX11_NUMERIC_LIMITS is defined" << endl;
  26. #else
  27. int max_digits10 = std::numeric_limits<double>::max_digits10;
  28. #endif
  29. cout << "Show all potentially significant decimal digits std::numeric_limits<double>::max_digits10 = "
  30. << max_digits10 << endl;
  31. cout.precision(max_digits10); //
  32. double x = 1.;
  33. double a = 10;
  34. double r = boost::math::gamma_q_inv(a ,x);
  35. cout << " x = " << x << ", = gamma_q_inv(a,x)" << r << endl; //
  36. return 0;
  37. } // int main()
  38. /*
  39. Output is:
  40. */