Imported Upstream version 1.49.0
[platform/upstream/boost.git] / 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)
5
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>
12 #include <fstream>
13
14 #include <boost/math/tools/test_data.hpp>
15
16 using namespace boost::math::tools;
17
18 //
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
22 // be thrown off:
23 //
24 float external_f;
25 float force_truncate(const float* f)
26 {
27    external_f = *f;
28    return external_f;
29 }
30
31 float truncate_to_float(boost::math::ntl::RR r)
32 {
33    float f = boost::math::tools::real_cast<float>(r);
34    return force_truncate(&f);
35 }
36
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);
42
43 struct ibeta_inv_data_generator
44 {
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_)
47    {
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);
61    }
62 };
63
64 int test_main(int argc, char*argv [])
65 {
66    boost::math::ntl::RR::SetPrecision(1000);
67    boost::math::ntl::RR::SetOutputPrecision(100);
68
69    bool cont;
70    std::string line;
71
72    parameter_info<boost::math::ntl::RR> arg1, arg2, arg3;
73    test_data<boost::math::ntl::RR> data;
74
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";
78
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);
82
83    arg1.type |= dummy_param;
84    arg2.type |= dummy_param;
85    arg3.type |= dummy_param;
86
87    data.insert(ibeta_inv_data_generator(), arg1, arg2, arg3);
88
89    line = "ibeta_inva_data.ipp";
90    std::ofstream ofs(line.c_str());
91    write_code(ofs, data, "ibeta_inva_data");
92    
93    return 0;
94 }
95