• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //  (C) Copyright John Maddock 2007.
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 <pch_light.hpp>
7 #include "test_bessel_i.hpp"
8 
9 //
10 // DESCRIPTION:
11 // ~~~~~~~~~~~~
12 //
13 // This file tests the bessel I function.  There are two sets of tests, spot
14 // tests which compare our results with selected values computed
15 // using the online special function calculator at
16 // functions.wolfram.com, while the bulk of the accuracy tests
17 // use values generated with NTL::RR at 1000-bit precision
18 // and our generic versions of these functions.
19 //
20 // Note that when this file is first run on a new platform many of
21 // these tests will fail: the default accuracy is 1 epsilon which
22 // is too tight for most platforms.  In this situation you will
23 // need to cast a human eye over the error rates reported and make
24 // a judgement as to whether they are acceptable.  Either way please
25 // report the results to the Boost mailing list.  Acceptable rates of
26 // error are marked up below as a series of regular expressions that
27 // identify the compiler/stdlib/platform/data-type/test-data/test-function
28 // along with the maximum expected peek and RMS mean errors for that
29 // test.
30 //
31 
expected_results()32 void expected_results()
33 {
34    //
35    // Define the max and mean errors expected for
36    // various compilers and platforms.
37    //
38    const char* largest_type;
39 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
40    if(boost::math::policies::digits<double, boost::math::policies::policy<> >() == boost::math::policies::digits<long double, boost::math::policies::policy<> >())
41    {
42       largest_type = "(long\\s+)?double";
43    }
44    else
45    {
46       largest_type = "long double";
47    }
48 #else
49    largest_type = "(long\\s+)?double";
50 #endif
51 
52    //
53    // Mac OS has higher error rates, why?
54    //
55    add_expected_result(
56       ".*",                          // compiler
57       ".*",                          // stdlib
58       "Mac OS",                      // platform
59       largest_type,                  // test type(s)
60       ".*",                          // test data group
61       ".*", 400, 200);               // test function
62    //
63    // G++ on Linux, results vary a bit by processor type,
64    // on Itanium results are *much* better than listed here,
65    // but x86 appears to have much less accurate std::pow
66    // that throws off the results for tgamma(long double)
67    // which then impacts on the Bessel functions:
68    //
69    add_expected_result(
70       ".*",                          // compiler
71       ".*",                          // stdlib
72       "linux",                       // platform
73       largest_type,                  // test type(s)
74       ".*Random.*",                    // test data group
75       ".*", 400, 200);               // test function
76 
77    add_expected_result(
78       "GNU.*",                       // compiler
79       ".*",                          // stdlib
80       "Win32.*",                     // platform
81       largest_type,                  // test type(s)
82       ".*Random.*",                  // test data group
83       ".*", 400, 200);               // test function
84    add_expected_result(
85       "GNU.*",                          // compiler
86       ".*",                          // stdlib
87       "Win32.*",                          // platform
88       largest_type,                  // test type(s)
89       ".*",                          // test data group
90       ".*", 30, 10);                 // test function
91    add_expected_result(
92       ".*",                          // compiler
93       ".*",                          // stdlib
94       ".*Solaris.*",                 // platform
95       largest_type,                  // test type(s)
96       ".*",                          // test data group
97       ".*", 500, 200);               // test function
98    add_expected_result(
99       ".*",                          // compiler
100       ".*",                          // stdlib
101       ".*",                          // platform
102       largest_type,                  // test type(s)
103       ".*",                          // test data group
104       ".*", 20, 10);                 // test function
105    //
106    // Set error rates a little higher for real_concept -
107    // now that we use a series approximation for small z
108    // that relies on tgamma the error rates are a little
109    // higher only when a Lanczos approximation is not available.
110    // All other types are unaffected.
111    //
112    add_expected_result(
113       ".*",                          // compiler
114       ".*",                          // stdlib
115       ".*",                          // platform
116       "real_concept",                // test type(s)
117       ".*",                          // test data group
118       ".*", 500, 200);               // test function
119    //
120    // Finish off by printing out the compiler/stdlib/platform names,
121    // we do this to make it easier to mark up expected error rates.
122    //
123    std::cout << "Tests run with " << BOOST_COMPILER << ", "
124       << BOOST_STDLIB << ", " << BOOST_PLATFORM << std::endl;
125 }
126 
BOOST_AUTO_TEST_CASE(test_main)127 BOOST_AUTO_TEST_CASE( test_main )
128 {
129 #ifdef TEST_GSL
130    gsl_set_error_handler_off();
131 #endif
132    expected_results();
133    BOOST_MATH_CONTROL_FP;
134 
135 #ifndef BOOST_MATH_BUGGY_LARGE_FLOAT_CONSTANTS
136    test_bessel(0.1F, "float");
137 #endif
138    test_bessel(0.1, "double");
139 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
140    test_bessel(0.1L, "long double");
141 #ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
142    test_bessel(boost::math::concepts::real_concept(0.1), "real_concept");
143 #endif
144 #else
145    std::cout << "<note>The long double tests have been disabled on this platform "
146       "either because the long double overloads of the usual math functions are "
147       "not available at all, or because they are too inaccurate for these tests "
148       "to pass.</note>" << std::endl;
149 #endif
150 }
151 
152 
153 
154 
155