]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/math/tools/ibeta_inv_data.cpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / libs / math / tools / ibeta_inv_data.cpp
CommitLineData
7c673cae
FG
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
20effc67 6#include "mp_t.hpp"
7c673cae
FG
7#include <boost/math/special_functions/beta.hpp>
8#include <boost/math/constants/constants.hpp>
9#include <boost/lexical_cast.hpp>
10#include <fstream>
11#include <boost/math/tools/test_data.hpp>
12#include <boost/random.hpp>
7c673cae
FG
13
14using namespace boost::math::tools;
15
16//
f67539c2 17// Force truncation to float precision of input values:
7c673cae
FG
18// we must ensure that the input values are exactly representable
19// in whatever type we are testing, or the output values will all
20// be thrown off:
21//
22float external_f;
23float force_truncate(const float* f)
24{
25 external_f = *f;
26 return external_f;
27}
28
29float truncate_to_float(mp_t r)
30{
31 float f = boost::math::tools::real_cast<float>(r);
32 return force_truncate(&f);
33}
34
35boost::mt19937 rnd;
36boost::uniform_real<float> ur_a(1.0F, 5.0F);
37boost::variate_generator<boost::mt19937, boost::uniform_real<float> > gen(rnd, ur_a);
38boost::uniform_real<float> ur_a2(0.0F, 100.0F);
39boost::variate_generator<boost::mt19937, boost::uniform_real<float> > gen2(rnd, ur_a2);
40
41struct ibeta_inv_data_generator
42{
43 boost::math::tuple<mp_t, mp_t, mp_t, mp_t, mp_t> operator()(mp_t ap, mp_t bp, mp_t x_)
44 {
45 float a = truncate_to_float(real_cast<float>(gen() * pow(mp_t(10), ap)));
46 float b = truncate_to_float(real_cast<float>(gen() * pow(mp_t(10), bp)));
47 float x = truncate_to_float(real_cast<float>(x_));
48 std::cout << a << " " << b << " " << x << std::flush;
49 mp_t inv = boost::math::ibeta_inv(mp_t(a), mp_t(b), mp_t(x));
50 std::cout << " " << inv << std::flush;
51 mp_t invc = boost::math::ibetac_inv(mp_t(a), mp_t(b), mp_t(x));
52 std::cout << " " << invc << std::endl;
53 return boost::math::make_tuple(a, b, x, inv, invc);
54 }
55};
56
57int main(int argc, char*argv [])
58{
59 bool cont;
60 std::string line;
61
62 parameter_info<mp_t> arg1, arg2, arg3;
63 test_data<mp_t> data;
64
65 std::cout << "Welcome.\n"
66 "This program will generate spot tests for the inverse incomplete beta function:\n"
67 " ibeta_inv(a, p) and ibetac_inv(a, q)\n\n";
68
69 arg1 = make_periodic_param(mp_t(-5), mp_t(6), 11);
70 arg2 = make_periodic_param(mp_t(-5), mp_t(6), 11);
71 arg3 = make_random_param(mp_t(0.0001), mp_t(1), 10);
72
73 arg1.type |= dummy_param;
74 arg2.type |= dummy_param;
75 arg3.type |= dummy_param;
76
77 data.insert(ibeta_inv_data_generator(), arg1, arg2, arg3);
78
79 line = "ibeta_inv_data.ipp";
80 std::ofstream ofs(line.c_str());
81 ofs << std::scientific << std::setprecision(40);
82 write_code(ofs, data, "ibeta_inv_data");
83
84 return 0;
85}
86