ellint_pi3_data.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. #include <boost/math/tools/test_data.hpp>
  7. #include <boost/test/included/prg_exec_monitor.hpp>
  8. #include <boost/math/special_functions/ellint_3.hpp>
  9. #include <fstream>
  10. #include <boost/math/tools/test_data.hpp>
  11. #include <boost/random.hpp>
  12. #include "mp_t.hpp"
  13. float extern_val;
  14. // confuse the compilers optimiser, and force a truncation to float precision:
  15. float truncate_to_float(float const * pf)
  16. {
  17. extern_val = *pf;
  18. return *pf;
  19. }
  20. boost::math::tuple<mp_t, mp_t> generate_data(mp_t n, mp_t phi)
  21. {
  22. static boost::mt19937 r;
  23. boost::uniform_real<float> ui(0, 1);
  24. float k = ui(r);
  25. mp_t kr(truncate_to_float(&k));
  26. mp_t result = boost::math::ellint_3(kr, n, phi);
  27. return boost::math::make_tuple(kr, result);
  28. }
  29. int cpp_main(int argc, char*argv [])
  30. {
  31. using namespace boost::math::tools;
  32. parameter_info<mp_t> arg1, arg2;
  33. test_data<mp_t> data;
  34. bool cont;
  35. std::string line;
  36. if(argc < 1)
  37. return 1;
  38. do{
  39. if(0 == get_user_parameter_info(arg1, "n"))
  40. return 1;
  41. if(0 == get_user_parameter_info(arg2, "phi"))
  42. return 1;
  43. data.insert(&generate_data, arg1, arg2);
  44. std::cout << "Any more data [y/n]?";
  45. std::getline(std::cin, line);
  46. boost::algorithm::trim(line);
  47. cont = (line == "y");
  48. }while(cont);
  49. std::cout << "Enter name of test data file [default=ellint_pi3_data.ipp]";
  50. std::getline(std::cin, line);
  51. boost::algorithm::trim(line);
  52. if(line == "")
  53. line = "ellint_pi3_data.ipp";
  54. std::ofstream ofs(line.c_str());
  55. line.erase(line.find('.'));
  56. ofs << std::scientific << std::setprecision(40);
  57. write_code(ofs, data, line.c_str());
  58. return 0;
  59. }