]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/math/tools/ibeta_invab_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)
6 #include <boost/math/special_functions/beta.hpp>
7 #include <boost/math/constants/constants.hpp>
8 #include <boost/lexical_cast.hpp>
10 #include <boost/math/tools/test_data.hpp>
11 #include <boost/random.hpp>
14 using namespace boost::math::tools
;
17 // Force trunctation to float precision of input values:
18 // we must ensure that the input values are exactly representable
19 // in whatever type we are testing, or the output values will all
23 float force_truncate(const float* f
)
29 float truncate_to_float(mp_t r
)
31 float f
= boost::math::tools::real_cast
<float>(r
);
32 return force_truncate(&f
);
36 boost::uniform_real
<float> ur_a(1.0F
, 5.0F
);
37 boost::variate_generator
<boost::mt19937
, boost::uniform_real
<float> > gen(rnd
, ur_a
);
38 boost::uniform_real
<float> ur_a2(0.0F
, 100.0F
);
39 boost::variate_generator
<boost::mt19937
, boost::uniform_real
<float> > gen2(rnd
, ur_a2
);
41 struct ibeta_inv_data_generator
43 boost::math::tuple
<mp_t
, mp_t
, mp_t
, mp_t
, mp_t
, mp_t
, mp_t
> operator()
44 (mp_t bp
, mp_t x_
, mp_t p_
)
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 float p
= truncate_to_float(real_cast
<float>(p_
));
49 std::cout
<< b
<< " " << x
<< " " << p
<< std::flush
;
50 mp_t inv
= boost::math::ibeta_inva(mp_t(b
), mp_t(x
), mp_t(p
));
51 std::cout
<< " " << inv
<< std::flush
;
52 mp_t invc
= boost::math::ibetac_inva(mp_t(b
), mp_t(x
), mp_t(p
));
53 std::cout
<< " " << invc
<< std::endl
;
54 mp_t invb
= boost::math::ibeta_invb(mp_t(b
), mp_t(x
), mp_t(p
));
55 std::cout
<< " " << invb
<< std::flush
;
56 mp_t invbc
= boost::math::ibetac_invb(mp_t(b
), mp_t(x
), mp_t(p
));
57 std::cout
<< " " << invbc
<< std::endl
;
58 return boost::math::make_tuple(b
, x
, p
, inv
, invc
, invb
, invbc
);
62 int main(int argc
, char*argv
[])
67 parameter_info
<mp_t
> arg1
, arg2
, arg3
;
70 std::cout
<< "Welcome.\n"
71 "This program will generate spot tests for the inverse incomplete beta function:\n"
72 " ibeta_inva(a, p) and ibetac_inva(a, q)\n\n";
74 arg1
= make_periodic_param(mp_t(-5), mp_t(6), 11);
75 arg2
= make_random_param(mp_t(0.0001), mp_t(1), 10);
76 arg3
= make_random_param(mp_t(0.0001), mp_t(1), 10);
78 arg1
.type
|= dummy_param
;
79 arg2
.type
|= dummy_param
;
80 arg3
.type
|= dummy_param
;
82 data
.insert(ibeta_inv_data_generator(), arg1
, arg2
, arg3
);
84 line
= "ibeta_inva_data.ipp";
85 std::ofstream
ofs(line
.c_str());
86 ofs
<< std::scientific
<< std::setprecision(40);
87 write_code(ofs
, data
, "ibeta_inva_data");