]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/math/tools/hyp_0f2_data.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / math / tools / hyp_0f2_data.cpp
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
6 #define BOOST_MATH_MAX_SERIES_ITERATION_POLICY 10000000
7
8 #include <boost/math/constants/constants.hpp>
9 #include <boost/lexical_cast.hpp>
10 #include <fstream>
11 #include <map>
12 #include <boost/math/tools/test_data.hpp>
13 #include <boost/random.hpp>
14 #include "mp_t.hpp"
15
16 using namespace boost::math::tools;
17 using namespace boost::math;
18 using namespace std;
19
20 struct hypergeometric_0f2_gen
21 {
22 mp_t operator()(mp_t b1, mp_t b2, mp_t z)
23 {
24 mp_t result = 0;
25 mp_t abs_result = 0;
26 mp_t term = 1;
27 mp_t k = 0;
28
29 do
30 {
31 result += term;
32 abs_result += fabs(term);
33 if (fabs(result) * boost::math::tools::epsilon<mp_t>() > fabs(term))
34 break;
35 ++k;
36 term /= b1++;
37 term /= b2++;
38 term /= k;
39 term *= z;
40 } while (true);
41 //
42 // check precision:
43 //
44 if (abs_result * boost::math::tools::epsilon<mp_t>() / fabs(result) > 1e-40)
45 throw std::domain_error("Unable to calculate result");
46
47 std::cout << b1 << " " << b2 << " " << z << " " << result << std::endl;
48 return result;
49 }
50 };
51
52 int main(int, char* [])
53 {
54 parameter_info<mp_t> arg1, arg2, arg3, arg4;
55 test_data<mp_t> data;
56
57 std::cout << "Welcome.\n"
58 "This program will generate spot tests for 2F0:\n";
59
60 std::string line;
61 bool cont = true;
62
63 while (cont)
64 {
65 float range;
66 std::cout << "Enter the range to calculate over for b1 and b2 (single value, range will be -x to x): ";
67 std::cin >> range;
68
69 float z_range;
70 std::cout << "Enter the range to calculate over for z (single value, range will be -x to x): ";
71 std::cin >> z_range;
72
73 int num_spots;
74 std::cout << "Enter how many test points to calculate: ";
75 std::cin >> num_spots;
76
77 std::vector<mp_t> v;
78 random_ns::mt19937 rnd;
79 random_ns::uniform_real_distribution<float> ur_a(-range, range);
80 random_ns::uniform_real_distribution<float> ur_z(-z_range, z_range);
81
82 do
83 {
84 mp_t b1 = ur_a(rnd);
85 mp_t b2 = ur_a(rnd);
86 mp_t z = ur_z(rnd);
87
88 arg1 = make_single_param(b1);
89 arg2 = make_single_param(b2);
90 arg3 = make_single_param(z);
91 data.insert(hypergeometric_0f2_gen(), arg1, arg2, arg3);
92 } while (num_spots--);
93
94 std::cout << "Any more data?";
95 std::cin >> cont;
96
97 }
98
99
100
101 std::cout << "Enter name of test data file [default=hypergeometric_0f2.ipp]";
102 std::getline(std::cin, line);
103 boost::algorithm::trim(line);
104 if(line == "")
105 line = "hypergeometric_0f2.ipp";
106 std::ofstream ofs(line.c_str());
107 ofs << std::scientific << std::setprecision(40);
108 write_code(ofs, data, line.c_str());
109
110 return 0;
111 }
112
113