• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright John Maddock 2013.
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 
7 //[special_data_example
8 
9 #include <boost/multiprecision/mpfr.hpp>
10 #include <boost/math/tools/test_data.hpp>
11 #include <boost/test/included/prg_exec_monitor.hpp>
12 #include <boost/math/tools/tuple.hpp>
13 #include <fstream>
14 
15 using namespace boost::math::tools;
16 using namespace boost::math;
17 using namespace std;
18 using namespace boost::multiprecision;
19 
20 typedef number<mpfr_float_backend<1000> > mp_type;
21 
22 
generate(mp_type a)23 boost::math::tuple<mp_type, mp_type, mp_type> generate(mp_type a)
24 {
25    mp_type tg, lg;
26    mpfr_gamma(tg.backend().data(), a.backend().data(), GMP_RNDN);
27    mpfr_lngamma(lg.backend().data(), a.backend().data(), GMP_RNDN);
28    return boost::math::make_tuple(a, tg, lg);
29 }
30 
cpp_main(int argc,char * argv[])31 int cpp_main(int argc, char*argv [])
32 {
33    parameter_info<mp_type> arg1, arg2;
34    test_data<mp_type> data;
35 
36    bool cont;
37    std::string line;
38 
39    if(argc < 1)
40       return 1;
41 
42    do{
43       //
44       // User interface which prompts for
45       // range of input parameters:
46       //
47       if(0 == get_user_parameter_info(arg1, "a"))
48          return 1;
49       arg1.type |= dummy_param;
50 
51       data.insert(&generate, arg1);
52 
53       std::cout << "Any more data [y/n]?";
54       std::getline(std::cin, line);
55       boost::algorithm::trim(line);
56       cont = (line == "y");
57    }while(cont);
58    //
59    // Just need to write the results to a file:
60    //
61    std::cout << "Enter name of test data file [default=gamma.ipp]";
62    std::getline(std::cin, line);
63    boost::algorithm::trim(line);
64    if(line == "")
65       line = "gamma.ipp";
66    std::ofstream ofs(line.c_str());
67    line.erase(line.find('.'));
68    ofs << std::scientific << std::setprecision(500);
69    write_code(ofs, data, line.c_str());
70 
71    return 0;
72 }
73 
74 //]
75 
76