7fc446381af3c1c6c5df028c164d8bcb26a5bedf
[platform/upstream/boost.git] / libs / math / test / test_zeta.hpp
1 // Copyright John Maddock 2006.
2 // Copyright Paul A. Bristow 2007, 2009
3 //  Use, modification and distribution are subject to the
4 //  Boost Software License, Version 1.0. (See accompanying file
5 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6
7 #include <boost/math/concepts/real_concept.hpp>
8 #include <boost/math/special_functions/math_fwd.hpp>
9 #include <boost/test/test_exec_monitor.hpp>
10 #include <boost/test/floating_point_comparison.hpp>
11 #include <boost/math/tools/stats.hpp>
12 #include <boost/math/tools/test.hpp>
13 #include <boost/math/constants/constants.hpp>
14 #include <boost/type_traits/is_floating_point.hpp>
15 #include <boost/array.hpp>
16 #include "functor.hpp"
17
18 #include "handle_test_result.hpp"
19 #include "test_zeta_hooks.hpp"
20 #include "table_type.hpp"
21
22 #ifndef SC_
23 #define SC_(x) static_cast<typename table_type<T>::type>(BOOST_JOIN(x, L))
24 #endif
25
26 template <class Real, class T>
27 void do_test_zeta(const T& data, const char* type_name, const char* test_name)
28 {
29    //
30    // test zeta(T) against data:
31    //
32    using namespace std;
33    typedef typename T::value_type row_type;
34    typedef Real                   value_type;
35
36    std::cout << test_name << " with type " << type_name << std::endl;
37
38    typedef value_type (*pg)(value_type);
39 #if defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
40    pg funcp = boost::math::zeta<value_type>;
41 #else
42    pg funcp = boost::math::zeta;
43 #endif
44
45    boost::math::tools::test_result<value_type> result;
46    //
47    // test zeta against data:
48    //
49    result = boost::math::tools::test_hetero<Real>(
50       data,
51       bind_func<Real>(funcp, 0),
52       extract_result<Real>(1));
53    handle_test_result(result, data[result.worst()], result.worst(), type_name, "boost::math::zeta", test_name);
54 #ifdef TEST_OTHER
55    if(boost::is_floating_point<value_type>::value)
56    {
57       funcp = other::zeta;
58
59       result = boost::math::tools::test_hetero<Real>(
60          data,
61          bind_func<Real>(funcp, 0),
62          extract_result<Real>(1));
63       handle_test_result(result, data[result.worst()], result.worst(), type_name, "other::zeta", test_name);
64    }
65 #endif
66    std::cout << std::endl;
67 }
68 template <class T>
69 void test_zeta(T, const char* name)
70 {
71    //
72    // The actual test data is rather verbose, so it's in a separate file
73    //
74 #include "zeta_data.ipp"
75    do_test_zeta<T>(zeta_data, name, "Zeta: Random values greater than 1");
76 #include "zeta_neg_data.ipp"
77    do_test_zeta<T>(zeta_neg_data, name, "Zeta: Random values less than 1");
78 #include "zeta_1_up_data.ipp"
79    do_test_zeta<T>(zeta_1_up_data, name, "Zeta: Values close to and greater than 1");
80 #include "zeta_1_below_data.ipp"
81    do_test_zeta<T>(zeta_1_below_data, name, "Zeta: Values close to and less than 1");
82 }
83
84 extern "C" double zetac(double);
85
86 template <class T>
87 void test_spots(T, const char* t)
88 {
89    std::cout << "Testing basic sanity checks for type " << t << std::endl;
90    //
91    // Basic sanity checks, tolerance is either 5 or 10 epsilon 
92    // expressed as a percentage:
93    //
94    T tolerance = boost::math::tools::epsilon<T>() * 100 *
95       (boost::is_floating_point<T>::value ? 5 : 10);
96    BOOST_CHECK_CLOSE(::boost::math::zeta(static_cast<T>(0.125)), static_cast<T>(-0.63277562349869525529352526763564627152686379131122L), tolerance);
97    BOOST_CHECK_CLOSE(::boost::math::zeta(static_cast<T>(1023) / static_cast<T>(1024)), static_cast<T>(-1023.4228554489429786541032870895167448906103303056L), tolerance);
98    BOOST_CHECK_CLOSE(::boost::math::zeta(static_cast<T>(1025) / static_cast<T>(1024)), static_cast<T>(1024.5772867695045940578681624248887776501597556226L), tolerance);
99    BOOST_CHECK_CLOSE(::boost::math::zeta(static_cast<T>(0.5)), static_cast<T>(-1.46035450880958681288949915251529801246722933101258149054289L), tolerance);
100    BOOST_CHECK_CLOSE(::boost::math::zeta(static_cast<T>(1.125)), static_cast<T>(8.5862412945105752999607544082693023591996301183069L), tolerance);
101    BOOST_CHECK_CLOSE(::boost::math::zeta(static_cast<T>(2)), static_cast<T>(1.6449340668482264364724151666460251892189499012068L), tolerance);
102    BOOST_CHECK_CLOSE(::boost::math::zeta(static_cast<T>(3.5)), static_cast<T>(1.1267338673170566464278124918549842722219969574036L), tolerance);
103    BOOST_CHECK_CLOSE(::boost::math::zeta(static_cast<T>(4)), static_cast<T>(1.08232323371113819151600369654116790277475095191872690768298L), tolerance);
104    BOOST_CHECK_CLOSE(::boost::math::zeta(4 + static_cast<T>(1) / 1024), static_cast<T>(1.08225596856391369799036835439238249195298434901488518878804L), tolerance);
105    BOOST_CHECK_CLOSE(::boost::math::zeta(static_cast<T>(4.5)), static_cast<T>(1.05470751076145426402296728896028011727249383295625173068468L), tolerance);
106    BOOST_CHECK_CLOSE(::boost::math::zeta(static_cast<T>(6.5)), static_cast<T>(1.01200589988852479610078491680478352908773213619144808841031L), tolerance);
107    BOOST_CHECK_CLOSE(::boost::math::zeta(static_cast<T>(7.5)), static_cast<T>(1.00582672753652280770224164440459408011782510096320822989663L), tolerance);
108    BOOST_CHECK_CLOSE(::boost::math::zeta(static_cast<T>(8.125)), static_cast<T>(1.0037305205308161603183307711439385250181080293472L), 2 * tolerance);
109    BOOST_CHECK_CLOSE(::boost::math::zeta(static_cast<T>(16.125)), static_cast<T>(1.0000140128224754088474783648500235958510030511915L), tolerance);
110    BOOST_CHECK_CLOSE(::boost::math::zeta(static_cast<T>(0)), static_cast<T>(-0.5L), tolerance);
111    BOOST_CHECK_CLOSE(::boost::math::zeta(static_cast<T>(-0.125)), static_cast<T>(-0.39906966894504503550986928301421235400280637468895L), tolerance);
112    BOOST_CHECK_CLOSE(::boost::math::zeta(static_cast<T>(-1)), static_cast<T>(-0.083333333333333333333333333333333333333333333333333L), tolerance);
113    BOOST_CHECK_CLOSE(::boost::math::zeta(static_cast<T>(-2)), static_cast<T>(0L), tolerance);
114    BOOST_CHECK_CLOSE(::boost::math::zeta(static_cast<T>(-2.5)), static_cast<T>(0.0085169287778503305423585670283444869362759902200745L), tolerance * 3);
115    BOOST_CHECK_CLOSE(::boost::math::zeta(static_cast<T>(-3)), static_cast<T>(0.0083333333333333333333333333333333333333333333333333L), tolerance);
116    BOOST_CHECK_CLOSE(::boost::math::zeta(static_cast<T>(-4)), static_cast<T>(0), tolerance);
117    BOOST_CHECK_CLOSE(::boost::math::zeta(static_cast<T>(-20)), static_cast<T>(0), tolerance * 100);
118    BOOST_CHECK_CLOSE(::boost::math::zeta(static_cast<T>(-21)), static_cast<T>(-281.46014492753623188405797101449275362318840579710L), tolerance * 100);
119    BOOST_CHECK_CLOSE(::boost::math::zeta(static_cast<T>(-30.125)), static_cast<T>(2.2762941726834511267740045451463455513839970804578e7L), tolerance * 100);
120 }
121