sinc_data.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 <boost/math/special_functions/digamma.hpp>
  6. #include <boost/test/included/prg_exec_monitor.hpp>
  7. #include <fstream>
  8. #include <boost/math/tools/test_data.hpp>
  9. #include "mp_t.hpp"
  10. using namespace boost::math::tools;
  11. using namespace std;
  12. float external_f;
  13. float force_truncate(const float* f)
  14. {
  15. external_f = *f;
  16. return external_f;
  17. }
  18. float truncate_to_float(mp_t r)
  19. {
  20. float f = boost::math::tools::real_cast<float>(r);
  21. return force_truncate(&f);
  22. }
  23. template <class T>
  24. T naive_sinc(T const& x)
  25. {
  26. using std::sin;
  27. return sin(x) / x;
  28. }
  29. int cpp_main(int argc, char*argv [])
  30. {
  31. parameter_info<mp_t> arg1;
  32. test_data<mp_t> data;
  33. bool cont;
  34. std::string line;
  35. std::cout << "Welcome.\n"
  36. "This program will generate spot tests for the sinc function:\n"
  37. " sinc_pi(z)\n\n";
  38. do{
  39. if(0 == get_user_parameter_info(arg1, "z"))
  40. return 1;
  41. data.insert(&::naive_sinc<mp_t>, arg1);
  42. std::cout << "Any more data [y/n]?";
  43. std::getline(std::cin, line);
  44. boost::algorithm::trim(line);
  45. cont = (line == "y");
  46. }while(cont);
  47. std::cout << "Enter name of test data file [default=sinc_data.ipp]";
  48. std::getline(std::cin, line);
  49. boost::algorithm::trim(line);
  50. if(line == "")
  51. line = "sinc_data.ipp";
  52. std::ofstream ofs(line.c_str());
  53. ofs << std::scientific << std::setprecision(40);
  54. write_code(ofs, data, "sinc_data");
  55. return 0;
  56. }