• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //  Copyright (c) 2013 Anton Bikineev
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 
8 #ifdef _MSC_VER
9 #  pragma warning(disable : 4756) // overflow in constant arithmetic
10 // Constants are too big for float case, but this doesn't matter for test.
11 #endif
12 
13 #include "test_bessel_k_prime.hpp"
14 
15 //
16 // DESCRIPTION:
17 // ~~~~~~~~~~~~
18 //
19 // This file tests the bessel K functions derivatives.  There are two sets of tests, spot
20 // tests which compare our results with selected values computed
21 // using the online special function calculator at
22 // functions.wolfram.com, while the bulk of the accuracy tests
23 // use values generated with Boost.Multiprecision at 50 precision
24 // and our generic versions of these functions.
25 //
26 // Note that when this file is first run on a new platform many of
27 // these tests will fail: the default accuracy is 1 epsilon which
28 // is too tight for most platforms.  In this situation you will
29 // need to cast a human eye over the error rates reported and make
30 // a judgement as to whether they are acceptable.  Either way please
31 // report the results to the Boost mailing list.  Acceptable rates of
32 // error are marked up below as a series of regular expressions that
33 // identify the compiler/stdlib/platform/data-type/test-data/test-function
34 // along with the maximum expected peek and RMS mean errors for that
35 // test.
36 //
37 
expected_results()38 void expected_results()
39 {
40    //
41    // Define the max and mean errors expected for
42    // various compilers and platforms.
43    //
44    const char* largest_type;
45 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
46    if(boost::math::policies::digits<double, boost::math::policies::policy<> >() == boost::math::policies::digits<long double, boost::math::policies::policy<> >())
47    {
48       largest_type = "(long\\s+)?double|real_concept";
49    }
50    else
51    {
52       largest_type = "long double|real_concept";
53    }
54 #else
55    largest_type = "(long\\s+)?double|real_concept";
56 #endif
57    //
58    // On MacOS X cyl_bessel_k has much higher error levels than
59    // expected: given that the implementation is basically
60    // just a continued fraction evaluation combined with
61    // exponentiation, we conclude that exp and pow are less
62    // accurate on this platform, especially when the result
63    // is outside the range of a double.
64    //
65    add_expected_result(
66       ".*",                          // compiler
67       ".*",                          // stdlib
68       "Mac OS",                      // platform
69       largest_type,                  // test type(s)
70       ".*",                          // test data group
71       ".*", 4000, 1300);             // test function
72 
73    add_expected_result(
74       "GNU.*",                          // compiler
75       ".*",                          // stdlib
76       "Win32.*",                          // platform
77       largest_type,                  // test type(s)
78       ".*large.*",                   // test data group
79       ".*", 250, 100);                 // test function
80    add_expected_result(
81       ".*",                          // compiler
82       ".*",                          // stdlib
83       ".*",                          // platform
84       largest_type,                  // test type(s)
85       ".*large.*",                   // test data group
86       ".*", 100, 75);                // test function
87    add_expected_result(
88       ".*",                          // compiler
89       ".*",                          // stdlib
90       ".*",                          // platform
91       largest_type,                  // test type(s)
92       ".*",                          // test data group
93       ".*", 35, 15);                 // test function
94    //
95    // Finish off by printing out the compiler/stdlib/platform names,
96    // we do this to make it easier to mark up expected error rates.
97    //
98    std::cout << "Tests run with " << BOOST_COMPILER << ", "
99       << BOOST_STDLIB << ", " << BOOST_PLATFORM << std::endl;
100 }
101 
BOOST_AUTO_TEST_CASE(test_main)102 BOOST_AUTO_TEST_CASE( test_main )
103 {
104 #ifdef TEST_GSL
105    gsl_set_error_handler_off();
106 #endif
107    expected_results();
108    BOOST_MATH_CONTROL_FP;
109 
110 #ifndef BOOST_MATH_BUGGY_LARGE_FLOAT_CONSTANTS
111    test_bessel(0.1F, "float");
112 #endif
113    test_bessel(0.1, "double");
114 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
115    test_bessel(0.1L, "long double");
116 #ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
117    test_bessel(boost::math::concepts::real_concept(0.1), "real_concept");
118 #endif
119 #else
120    std::cout << "<note>The long double tests have been disabled on this platform "
121       "either because the long double overloads of the usual math functions are "
122       "not available at all, or because they are too inaccurate for these tests "
123       "to pass.</note>" << std::endl;
124 #endif
125 }
126 
127 
128 
129 
130