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