]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/math/tools/beta_data.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / math / tools / beta_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 #include <boost/math/special_functions/gamma.hpp>
7 #include <boost/math/constants/constants.hpp>
8 #include <boost/math/tools/test_data.hpp>
9 #include <fstream>
10 #include "mp_t.hpp"
11
12 using namespace boost::math::tools;
13
14 struct beta_data_generator
15 {
16 mp_t operator()(mp_t a, mp_t b)
17 {
18 if(a < b)
19 throw std::domain_error("");
20 // very naively calculate spots:
21 mp_t g1, g2, g3;
22 int s1, s2, s3;
23 g1 = boost::math::lgamma(a, &s1);
24 g2 = boost::math::lgamma(b, &s2);
25 g3 = boost::math::lgamma(a+b, &s3);
26 g1 += g2 - g3;
27 g1 = exp(g1);
28 g1 *= s1 * s2 * s3;
29 return g1;
30 }
31 };
32
33
34 int main()
35 {
36 parameter_info<mp_t> arg1, arg2;
37 test_data<mp_t> data;
38
39 std::cout << "Welcome.\n"
40 "This program will generate spot tests for the beta function:\n"
41 " beta(a, b)\n\n";
42
43 bool cont;
44 std::string line;
45
46 do{
47 get_user_parameter_info(arg1, "a");
48 get_user_parameter_info(arg2, "b");
49 data.insert(beta_data_generator(), arg1, arg2);
50
51 std::cout << "Any more data [y/n]?";
52 std::getline(std::cin, line);
53 boost::algorithm::trim(line);
54 cont = (line == "y");
55 }while(cont);
56
57 std::cout << "Enter name of test data file [default=beta_data.ipp]";
58 std::getline(std::cin, line);
59 boost::algorithm::trim(line);
60 if(line == "")
61 line = "beta_data.ipp";
62 std::ofstream ofs(line.c_str());
63 ofs << std::scientific << std::setprecision(40);
64 write_code(ofs, data, "beta_data");
65
66 return 0;
67 }
68