tgamma_ratio_data.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 <fstream>
  7. #include <boost/math/tools/test_data.hpp>
  8. #include "mp_t.hpp"
  9. using namespace boost::math::tools;
  10. using namespace std;
  11. boost::math::tuple<mp_t, mp_t>
  12. tgamma_ratio(const mp_t& a, const mp_t& delta)
  13. {
  14. if(delta > a)
  15. throw std::domain_error("");
  16. mp_t tg = boost::math::tgamma(a);
  17. mp_t r1 = tg / boost::math::tgamma(a + delta);
  18. mp_t r2 = tg / boost::math::tgamma(a - delta);
  19. if((r1 > (std::numeric_limits<float>::max)()) || (r2 > (std::numeric_limits<float>::max)()))
  20. throw std::domain_error("");
  21. return boost::math::make_tuple(r1, r2);
  22. }
  23. mp_t tgamma_ratio2(const mp_t& a, const mp_t& b)
  24. {
  25. return boost::math::tgamma(a) / boost::math::tgamma(b);
  26. }
  27. int main(int argc, char*argv [])
  28. {
  29. parameter_info<mp_t> arg1, arg2;
  30. test_data<mp_t> data;
  31. bool cont;
  32. std::string line;
  33. if((argc >= 2) && (strcmp(argv[1], "--ratio") == 0))
  34. {
  35. std::cout << "Welcome.\n"
  36. "This program will generate spot tests for the function tgamma_ratio(a, b)\n\n";
  37. do{
  38. if(0 == get_user_parameter_info(arg1, "a"))
  39. return 1;
  40. if(0 == get_user_parameter_info(arg2, "b"))
  41. return 1;
  42. data.insert(&tgamma_ratio2, arg1, arg2);
  43. std::cout << "Any more data [y/n]?";
  44. std::getline(std::cin, line);
  45. boost::algorithm::trim(line);
  46. cont = (line == "y");
  47. }while(cont);
  48. }
  49. else
  50. {
  51. std::cout << "Welcome.\n"
  52. "This program will generate spot tests for the function tgamma_delta_ratio(a, delta)\n\n";
  53. do{
  54. if(0 == get_user_parameter_info(arg1, "a"))
  55. return 1;
  56. if(0 == get_user_parameter_info(arg2, "delta"))
  57. return 1;
  58. data.insert(&tgamma_ratio, arg1, arg2);
  59. std::cout << "Any more data [y/n]?";
  60. std::getline(std::cin, line);
  61. boost::algorithm::trim(line);
  62. cont = (line == "y");
  63. }while(cont);
  64. }
  65. std::cout << "Enter name of test data file [default=tgamma_ratio_data.ipp]";
  66. std::getline(std::cin, line);
  67. boost::algorithm::trim(line);
  68. if(line == "")
  69. line = "tgamma_ratio_data.ipp";
  70. std::ofstream ofs(line.c_str());
  71. ofs << std::scientific << std::setprecision(40);
  72. write_code(ofs, data, "tgamma_ratio_data");
  73. return 0;
  74. }