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