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/bindings/rr.hpp>
7 #include <boost/test/included/test_exec_monitor.hpp>
8 #include <boost/math/special_functions/beta.hpp>
9 #include <boost/math/constants/constants.hpp>
10 #include <boost/math/tools/test.hpp>
11 #include <boost/lexical_cast.hpp>
14 #include <boost/math/tools/test_data.hpp>
16 using namespace boost::math::tools;
19 // Force trunctation to float precision of input values:
20 // we must ensure that the input values are exactly representable
21 // in whatever type we are testing, or the output values will all
25 float force_truncate(const float* f)
31 float truncate_to_float(boost::math::ntl::RR r)
33 float f = boost::math::tools::real_cast<float>(r);
34 return force_truncate(&f);
37 std::tr1::mt19937 rnd;
38 std::tr1::uniform_real<float> ur_a(1.0F, 5.0F);
39 std::tr1::variate_generator<std::tr1::mt19937, std::tr1::uniform_real<float> > gen(rnd, ur_a);
40 std::tr1::uniform_real<float> ur_a2(0.0F, 100.0F);
41 std::tr1::variate_generator<std::tr1::mt19937, std::tr1::uniform_real<float> > gen2(rnd, ur_a2);
43 struct ibeta_inv_data_generator
45 boost::math::tuple<boost::math::ntl::RR, boost::math::ntl::RR, boost::math::ntl::RR, boost::math::ntl::RR, boost::math::ntl::RR, boost::math::ntl::RR, boost::math::ntl::RR> operator()
46 (boost::math::ntl::RR bp, boost::math::ntl::RR x_, boost::math::ntl::RR p_)
48 float b = truncate_to_float(real_cast<float>(gen() * pow(boost::math::ntl::RR(10), bp)));
49 float x = truncate_to_float(real_cast<float>(x_));
50 float p = truncate_to_float(real_cast<float>(p_));
51 std::cout << b << " " << x << " " << p << std::flush;
52 boost::math::ntl::RR inv = boost::math::ibeta_inva(boost::math::ntl::RR(b), boost::math::ntl::RR(x), boost::math::ntl::RR(p));
53 std::cout << " " << inv << std::flush;
54 boost::math::ntl::RR invc = boost::math::ibetac_inva(boost::math::ntl::RR(b), boost::math::ntl::RR(x), boost::math::ntl::RR(p));
55 std::cout << " " << invc << std::endl;
56 boost::math::ntl::RR invb = boost::math::ibeta_invb(boost::math::ntl::RR(b), boost::math::ntl::RR(x), boost::math::ntl::RR(p));
57 std::cout << " " << invb << std::flush;
58 boost::math::ntl::RR invbc = boost::math::ibetac_invb(boost::math::ntl::RR(b), boost::math::ntl::RR(x), boost::math::ntl::RR(p));
59 std::cout << " " << invbc << std::endl;
60 return boost::math::make_tuple(b, x, p, inv, invc, invb, invbc);
64 int test_main(int argc, char*argv [])
66 boost::math::ntl::RR::SetPrecision(1000);
67 boost::math::ntl::RR::SetOutputPrecision(100);
72 parameter_info<boost::math::ntl::RR> arg1, arg2, arg3;
73 test_data<boost::math::ntl::RR> data;
75 std::cout << "Welcome.\n"
76 "This program will generate spot tests for the inverse incomplete beta function:\n"
77 " ibeta_inva(a, p) and ibetac_inva(a, q)\n\n";
79 arg1 = make_periodic_param(boost::math::ntl::RR(-5), boost::math::ntl::RR(6), 11);
80 arg2 = make_random_param(boost::math::ntl::RR(0.0001), boost::math::ntl::RR(1), 10);
81 arg3 = make_random_param(boost::math::ntl::RR(0.0001), boost::math::ntl::RR(1), 10);
83 arg1.type |= dummy_param;
84 arg2.type |= dummy_param;
85 arg3.type |= dummy_param;
87 data.insert(ibeta_inv_data_generator(), arg1, arg2, arg3);
89 line = "ibeta_inva_data.ipp";
90 std::ofstream ofs(line.c_str());
91 write_code(ofs, data, "ibeta_inva_data");