log1p_expm1_data.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 <fstream>
  6. #include <boost/math/tools/test_data.hpp>
  7. #include <boost/math/special_functions/log1p.hpp>
  8. #include <boost/math/special_functions/expm1.hpp>
  9. #include "mp_t.hpp"
  10. using namespace boost::math::tools;
  11. using namespace std;
  12. struct data_generator
  13. {
  14. boost::math::tuple<mp_t, mp_t> operator()(mp_t z)
  15. {
  16. return boost::math::make_tuple(boost::math::log1p(z), boost::math::expm1(z));
  17. }
  18. };
  19. int main(int argc, char* argv[])
  20. {
  21. parameter_info<mp_t> arg1;
  22. test_data<mp_t> data;
  23. std::cout << "Welcome.\n"
  24. "This program will generate spot tests for the log1p and expm1 functions:\n\n";
  25. bool cont;
  26. std::string line;
  27. do{
  28. if(0 == get_user_parameter_info(arg1, "z"))
  29. return 1;
  30. data.insert(data_generator(), arg1);
  31. std::cout << "Any more data [y/n]?";
  32. std::getline(std::cin, line);
  33. boost::algorithm::trim(line);
  34. cont = (line == "y");
  35. }while(cont);
  36. std::cout << "Enter name of test data file [default=log1p_expm1_data.ipp]";
  37. std::getline(std::cin, line);
  38. boost::algorithm::trim(line);
  39. if(line == "")
  40. line = "log1p_expm1_data.ipp";
  41. std::ofstream ofs(line.c_str());
  42. ofs << std::scientific << std::setprecision(40);
  43. write_code(ofs, data, "log1p_expm1_data");
  44. return 0;
  45. }