• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //  Copyright John Maddock 2008.
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/constants/constants.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 struct asinh_data_generator
15 {
operator ()asinh_data_generator16    mp_t operator()(mp_t z)
17    {
18       std::cout << z << " ";
19       mp_t result = log(z + sqrt(z * z + 1));
20       std::cout << result << std::endl;
21       return result;
22    }
23 };
24 
25 struct acosh_data_generator
26 {
operator ()acosh_data_generator27    mp_t operator()(mp_t z)
28    {
29       std::cout << z << " ";
30       mp_t result = log(z + sqrt(z * z - 1));
31       std::cout << result << std::endl;
32       return result;
33    }
34 };
35 
36 struct atanh_data_generator
37 {
operator ()atanh_data_generator38    mp_t operator()(mp_t z)
39    {
40       std::cout << z << " ";
41       mp_t result = log((z + 1) / (1 - z)) / 2;
42       std::cout << result << std::endl;
43       return result;
44    }
45 };
46 
main(int argc,char * argv[])47 int main(int argc, char*argv [])
48 {
49    parameter_info<mp_t> arg1;
50    test_data<mp_t> data;
51    std::ofstream ofs;
52 
53    bool cont;
54    std::string line;
55 
56    std::cout << "Welcome.\n"
57       "This program will generate spot tests for the inverse hyperbolic sin function:\n";
58 
59    do{
60       if(0 == get_user_parameter_info(arg1, "z"))
61          return 1;
62       data.insert(asinh_data_generator(), arg1);
63 
64       std::cout << "Any more data [y/n]?";
65       std::getline(std::cin, line);
66       boost::algorithm::trim(line);
67       cont = (line == "y");
68    }while(cont);
69 
70    std::cout << "Enter name of test data file [default=asinh_data.ipp]";
71    std::getline(std::cin, line);
72    boost::algorithm::trim(line);
73    if(line == "")
74       line = "asinh_data.ipp";
75    ofs.open(line.c_str());
76    ofs << std::scientific << std::setprecision(40);
77    write_code(ofs, data, "asinh_data");
78    data.clear();
79 
80    std::cout << "Welcome.\n"
81       "This program will generate spot tests for the inverse hyperbolic cos function:\n";
82 
83    do{
84       if(0 == get_user_parameter_info(arg1, "z"))
85          return 1;
86       data.insert(acosh_data_generator(), arg1);
87 
88       std::cout << "Any more data [y/n]?";
89       std::getline(std::cin, line);
90       boost::algorithm::trim(line);
91       cont = (line == "y");
92    }while(cont);
93 
94    std::cout << "Enter name of test data file [default=acosh_data.ipp]";
95    std::getline(std::cin, line);
96    boost::algorithm::trim(line);
97    if(line == "")
98       line = "acosh_data.ipp";
99    ofs.close();
100    ofs.open(line.c_str());
101    ofs << std::scientific << std::setprecision(40);
102    write_code(ofs, data, "acosh_data");
103    data.clear();
104 
105    std::cout << "Welcome.\n"
106       "This program will generate spot tests for the inverse hyperbolic tan function:\n";
107 
108    do{
109       if(0 == get_user_parameter_info(arg1, "z"))
110          return 1;
111       data.insert(atanh_data_generator(), arg1);
112 
113       std::cout << "Any more data [y/n]?";
114       std::getline(std::cin, line);
115       boost::algorithm::trim(line);
116       cont = (line == "y");
117    }while(cont);
118 
119    std::cout << "Enter name of test data file [default=atanh_data.ipp]";
120    std::getline(std::cin, line);
121    boost::algorithm::trim(line);
122    if(line == "")
123       line = "atanh_data.ipp";
124    ofs.close();
125    ofs.open(line.c_str());
126    ofs << std::scientific << std::setprecision(40);
127    write_code(ofs, data, "atanh_data");
128 
129    return 0;
130 }
131 
132