gamma_P_inva_data.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // (C) Copyright John Maddock 2006.
  2. // Use, modification and distribution are subject to the
  3. // Boost Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #include <boost/math/special_functions/gamma.hpp>
  6. #include <boost/math/constants/constants.hpp>
  7. #include <boost/lexical_cast.hpp>
  8. #include <fstream>
  9. #include <boost/math/tools/test_data.hpp>
  10. #include "mp_t.hpp"
  11. using namespace boost::math::tools;
  12. //
  13. // Force trunctation to float precision of input values:
  14. // we must ensure that the input values are exactly representable
  15. // in whatever type we are testing, or the output values will all
  16. // be thrown off:
  17. //
  18. float external_f;
  19. float force_truncate(const float* f)
  20. {
  21. external_f = *f;
  22. return external_f;
  23. }
  24. float truncate_to_float(mp_t r)
  25. {
  26. float f = boost::math::tools::real_cast<float>(r);
  27. return force_truncate(&f);
  28. }
  29. struct gamma_inverse_generator_a
  30. {
  31. boost::math::tuple<mp_t, mp_t> operator()(const mp_t x, const mp_t p)
  32. {
  33. mp_t x1 = boost::math::gamma_p_inva(x, p);
  34. mp_t x2 = boost::math::gamma_q_inva(x, p);
  35. std::cout << "Inverse for " << x << " " << p << std::endl;
  36. return boost::math::make_tuple(x1, x2);
  37. }
  38. };
  39. int main(int argc, char*argv [])
  40. {
  41. bool cont;
  42. std::string line;
  43. parameter_info<mp_t> arg1, arg2;
  44. test_data<mp_t> data;
  45. std::cout << "Welcome.\n"
  46. "This program will generate spot tests for the inverse incomplete gamma function:\n"
  47. " gamma_p_inva(a, p) and gamma_q_inva(a, q)\n\n";
  48. arg1 = make_power_param<mp_t>(mp_t(0), -4, 24);
  49. arg2 = make_random_param<mp_t>(mp_t(0), mp_t(1), 15);
  50. data.insert(gamma_inverse_generator_a(), arg1, arg2);
  51. line = "igamma_inva_data.ipp";
  52. std::ofstream ofs(line.c_str());
  53. ofs << std::scientific << std::setprecision(40);
  54. write_code(ofs, data, "igamma_inva_data");
  55. return 0;
  56. }