• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //  (C) Copyright John Maddock 2018.
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_sinc.hpp"
8 #include <boost/multiprecision/cpp_bin_float.hpp>
9 #include <boost/math/special_functions/next.hpp>
10 
11 //
12 // DESCRIPTION:
13 // ~~~~~~~~~~~~
14 //
15 // This file tests the sinc_pi function.  There are two sets of tests, spot
16 // tests which compare our results with selected values computed
17 // using the online special function calculator at
18 // functions.wolfram.com, while the bulk of the accuracy tests
19 // use values generated with NTL::RR at 1000-bit precision
20 // and our generic versions of these functions.
21 //
22 // Note that when this file is first run on a new platform many of
23 // these tests will fail: the default accuracy is 1 epsilon which
24 // is too tight for most platforms.  In this situation you will
25 // need to cast a human eye over the error rates reported and make
26 // a judgement as to whether they are acceptable.  Either way please
27 // report the results to the Boost mailing list.  Acceptable rates of
28 // error are marked up below as a series of regular expressions that
29 // identify the compiler/stdlib/platform/data-type/test-data/test-function
30 // along with the maximum expected peek and RMS mean errors for that
31 // test.
32 //
33 
expected_results()34 void expected_results()
35 {
36    //
37    // Define the max and mean errors expected for
38    // various compilers and platforms.
39    //
40    add_expected_result(
41       ".*",                          // compiler
42       ".*",                          // stdlib
43       ".*",                          // platform
44       ".*",                          // test type(s)
45       ".*",                          // test data group
46       ".*", 3, 3);                   // test function
47    //
48    // Finish off by printing out the compiler/stdlib/platform names,
49    // we do this to make it easier to mark up expected error rates.
50    //
51    std::cout << "Tests run with " << BOOST_COMPILER << ", "
52       << BOOST_STDLIB << ", " << BOOST_PLATFORM << std::endl;
53 }
54 
55 template <class T>
test_close_to_transition()56 void test_close_to_transition()
57 {
58    T transition = 3.3f * boost::math::tools::forth_root_epsilon<T>();
59    T val = transition;
60 
61    for (unsigned i = 0; i < 100; ++i)
62    {
63       boost::multiprecision::cpp_bin_float_50 extended = val;
64       extended = sin(extended) / extended;
65       T expected = extended.template convert_to<T>();
66       T result = boost::math::sinc_pi(val);
67       BOOST_CHECK_LE(boost::math::epsilon_difference(result, expected), 3);
68       result = boost::math::sinc_pi(-val);
69       BOOST_CHECK_LE(boost::math::epsilon_difference(result, expected), 3);
70       val = boost::math::float_prior(val);
71    }
72    for (unsigned i = 0; i < 100; ++i)
73    {
74       boost::multiprecision::cpp_bin_float_50 extended = val;
75       extended = sin(extended) / extended;
76       T expected = extended.template convert_to<T>();
77       T result = boost::math::sinc_pi(val);
78       BOOST_CHECK_LE(boost::math::epsilon_difference(result, expected), 3);
79       result = boost::math::sinc_pi(-val);
80       BOOST_CHECK_LE(boost::math::epsilon_difference(result, expected), 3);
81       val = boost::math::float_next(val);
82    }
83 }
84 
85 
BOOST_AUTO_TEST_CASE(test_main)86 BOOST_AUTO_TEST_CASE( test_main )
87 {
88    BOOST_MATH_CONTROL_FP;
89 
90    expected_results();
91 
92    test_sinc(0.1F, "float");
93    test_close_to_transition<float>();
94    test_sinc(0.1, "double");
95    test_close_to_transition<double>();
96 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
97    test_sinc(0.1L, "long double");
98    test_close_to_transition<long double>();
99 #ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
100    test_sinc(boost::math::concepts::real_concept(0.1), "real_concept");
101 #endif
102 #else
103    std::cout << "<note>The long double tests have been disabled on this platform "
104       "either because the long double overloads of the usual math functions are "
105       "not available at all, or because they are too inaccurate for these tests "
106       "to pass.</note>" << std::endl;
107 #endif
108 }
109 
110 
111