cbrt_data.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 "mp_t.hpp"
  8. using namespace boost::math::tools;
  9. using namespace std;
  10. struct cube_data_generator
  11. {
  12. mp_t operator()(mp_t z)
  13. {
  14. mp_t result = z*z*z;
  15. // if result is out of range of a float,
  16. // don't include in test data as it messes up our results:
  17. if(result > (std::numeric_limits<float>::max)())
  18. throw std::domain_error("");
  19. if(result < (std::numeric_limits<float>::min)())
  20. throw std::domain_error("");
  21. return result;
  22. }
  23. };
  24. int main(int argc, char* argv[])
  25. {
  26. parameter_info<mp_t> arg1;
  27. test_data<mp_t> data;
  28. std::cout << "Welcome.\n"
  29. "This program will generate spot tests for the cbrt function:\n\n";
  30. bool cont;
  31. std::string line;
  32. do{
  33. if(0 == get_user_parameter_info(arg1, "z"))
  34. return 1;
  35. data.insert(cube_data_generator(), arg1);
  36. std::cout << "Any more data [y/n]?";
  37. std::getline(std::cin, line);
  38. boost::algorithm::trim(line);
  39. cont = (line == "y");
  40. }while(cont);
  41. std::cout << "Enter name of test data file [default=cbrt_data.ipp]";
  42. std::getline(std::cin, line);
  43. boost::algorithm::trim(line);
  44. if(line == "")
  45. line = "cbrt_data.ipp";
  46. std::ofstream ofs(line.c_str());
  47. ofs << std::scientific << std::setprecision(40);
  48. write_code(ofs, data, "cbrt_data");
  49. return 0;
  50. }