special_data.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright John Maddock 2006.
  2. // Use, modification and distribution are subject to the
  3. // Boost Software License, Version 1.0.
  4. // (See accompanying file LICENSE_1_0.txt
  5. // or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //[special_data_example
  7. #include <boost/multiprecision/cpp_dec_float.hpp>
  8. #include <boost/math/tools/test_data.hpp>
  9. #include <boost/test/included/prg_exec_monitor.hpp>
  10. #include <fstream>
  11. using namespace boost::math::tools;
  12. using namespace boost::math;
  13. using namespace std;
  14. using namespace boost::multiprecision;
  15. template <class T>
  16. T my_special(T a, T b)
  17. {
  18. // Implementation of my_special here...
  19. return a + b;
  20. }
  21. int cpp_main(int argc, char*argv [])
  22. {
  23. //
  24. // We'll use so many digits of precision that any
  25. // calculation errors will still leave us with
  26. // 40-50 good digits. We'll only run this program
  27. // once so it doesn't matter too much how long this takes!
  28. //
  29. typedef number<cpp_dec_float<500> > bignum;
  30. parameter_info<bignum> arg1, arg2;
  31. test_data<bignum> data;
  32. bool cont;
  33. std::string line;
  34. if(argc < 1)
  35. return 1;
  36. do{
  37. //
  38. // User interface which prompts for
  39. // range of input parameters:
  40. //
  41. if(0 == get_user_parameter_info(arg1, "a"))
  42. return 1;
  43. if(0 == get_user_parameter_info(arg2, "b"))
  44. return 1;
  45. //
  46. // Get a pointer to the function and call
  47. // test_data::insert to actually generate
  48. // the values.
  49. //
  50. bignum (*fp)(bignum, bignum) = &my_special;
  51. data.insert(fp, arg2, arg1);
  52. std::cout << "Any more data [y/n]?";
  53. std::getline(std::cin, line);
  54. boost::algorithm::trim(line);
  55. cont = (line == "y");
  56. }while(cont);
  57. //
  58. // Just need to write the results to a file:
  59. //
  60. std::cout << "Enter name of test data file [default=my_special.ipp]";
  61. std::getline(std::cin, line);
  62. boost::algorithm::trim(line);
  63. if(line == "")
  64. line = "my_special.ipp";
  65. std::ofstream ofs(line.c_str());
  66. line.erase(line.find('.'));
  67. ofs << std::scientific << std::setprecision(50);
  68. write_code(ofs, data, line.c_str());
  69. return 0;
  70. }
  71. //]