inv_hyp_data.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. #include <boost/math/constants/constants.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. struct asinh_data_generator
  12. {
  13. mp_t operator()(mp_t z)
  14. {
  15. std::cout << z << " ";
  16. mp_t result = log(z + sqrt(z * z + 1));
  17. std::cout << result << std::endl;
  18. return result;
  19. }
  20. };
  21. struct acosh_data_generator
  22. {
  23. mp_t operator()(mp_t z)
  24. {
  25. std::cout << z << " ";
  26. mp_t result = log(z + sqrt(z * z - 1));
  27. std::cout << result << std::endl;
  28. return result;
  29. }
  30. };
  31. struct atanh_data_generator
  32. {
  33. mp_t operator()(mp_t z)
  34. {
  35. std::cout << z << " ";
  36. mp_t result = log((z + 1) / (1 - z)) / 2;
  37. std::cout << result << std::endl;
  38. return result;
  39. }
  40. };
  41. int main(int argc, char*argv [])
  42. {
  43. parameter_info<mp_t> arg1;
  44. test_data<mp_t> data;
  45. std::ofstream ofs;
  46. bool cont;
  47. std::string line;
  48. std::cout << "Welcome.\n"
  49. "This program will generate spot tests for the inverse hyperbolic sin function:\n";
  50. do{
  51. if(0 == get_user_parameter_info(arg1, "z"))
  52. return 1;
  53. data.insert(asinh_data_generator(), arg1);
  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. std::cout << "Enter name of test data file [default=asinh_data.ipp]";
  60. std::getline(std::cin, line);
  61. boost::algorithm::trim(line);
  62. if(line == "")
  63. line = "asinh_data.ipp";
  64. ofs.open(line.c_str());
  65. ofs << std::scientific << std::setprecision(40);
  66. write_code(ofs, data, "asinh_data");
  67. data.clear();
  68. std::cout << "Welcome.\n"
  69. "This program will generate spot tests for the inverse hyperbolic cos function:\n";
  70. do{
  71. if(0 == get_user_parameter_info(arg1, "z"))
  72. return 1;
  73. data.insert(acosh_data_generator(), arg1);
  74. std::cout << "Any more data [y/n]?";
  75. std::getline(std::cin, line);
  76. boost::algorithm::trim(line);
  77. cont = (line == "y");
  78. }while(cont);
  79. std::cout << "Enter name of test data file [default=acosh_data.ipp]";
  80. std::getline(std::cin, line);
  81. boost::algorithm::trim(line);
  82. if(line == "")
  83. line = "acosh_data.ipp";
  84. ofs.close();
  85. ofs.open(line.c_str());
  86. ofs << std::scientific << std::setprecision(40);
  87. write_code(ofs, data, "acosh_data");
  88. data.clear();
  89. std::cout << "Welcome.\n"
  90. "This program will generate spot tests for the inverse hyperbolic tan function:\n";
  91. do{
  92. if(0 == get_user_parameter_info(arg1, "z"))
  93. return 1;
  94. data.insert(atanh_data_generator(), arg1);
  95. std::cout << "Any more data [y/n]?";
  96. std::getline(std::cin, line);
  97. boost::algorithm::trim(line);
  98. cont = (line == "y");
  99. }while(cont);
  100. std::cout << "Enter name of test data file [default=atanh_data.ipp]";
  101. std::getline(std::cin, line);
  102. boost::algorithm::trim(line);
  103. if(line == "")
  104. line = "atanh_data.ipp";
  105. ofs.close();
  106. ofs.open(line.c_str());
  107. ofs << std::scientific << std::setprecision(40);
  108. write_code(ofs, data, "atanh_data");
  109. return 0;
  110. }