]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/math/test/acosh_test.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / math / test / acosh_test.hpp
1 // unit test file acosh.hpp for the special functions test suite
2
3 // (C) Copyright Hubert Holin 2003.
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7
8
9 #include <functional>
10 #include <iomanip>
11 #include <iostream>
12
13 #define BOOST_TEST_MAiN
14 #include <boost/math/special_functions/acosh.hpp>
15
16
17 #include <boost/test/unit_test.hpp>
18
19
20 template<typename T>
21 T acosh_error_evaluator(T x)
22 {
23 using ::std::abs;
24 using ::std::sinh;
25 using ::std::cosh;
26
27 using ::std::numeric_limits;
28
29 using ::boost::math::acosh;
30
31
32 static T const epsilon = numeric_limits<float>::epsilon();
33
34 T y = cosh(x);
35 T z = acosh(y);
36
37 T absolute_error = abs(z-abs(x));
38 T relative_error = absolute_error*abs(sinh(x));
39 T scaled_error = relative_error/epsilon;
40
41 return(scaled_error);
42 }
43
44
45 BOOST_TEST_CASE_TEMPLATE_FUNCTION(acosh_test, T)
46 {
47 BOOST_TEST_MESSAGE("Testing acosh in the real domain for "
48 << string_type_name<T>::_() << ".");
49
50 for (int i = 0; i <= 100; i++)
51 {
52 T x = static_cast<T>(i-50)/static_cast<T>(5);
53
54 BOOST_CHECK_PREDICATE(::std::less_equal<T>(),
55 (acosh_error_evaluator(x))
56 (static_cast<T>(4)));
57 }
58 // special cases for bug report: https://svn.boost.org/trac/boost/ticket/5113
59 T x = 1e-2f;
60 BOOST_CHECK_PREDICATE(::std::less_equal<T>(),
61 (acosh_error_evaluator(x))
62 (static_cast<T>(4)));
63 x = 1e-3f;
64 BOOST_CHECK_PREDICATE(::std::less_equal<T>(),
65 (acosh_error_evaluator(x))
66 (static_cast<T>(4)));
67 x = 1e-4f;
68 BOOST_CHECK_PREDICATE(::std::less_equal<T>(),
69 (acosh_error_evaluator(x))
70 (static_cast<T>(4)));
71 x = 1e-5f;
72 BOOST_CHECK_PREDICATE(::std::less_equal<T>(),
73 (acosh_error_evaluator(x))
74 (static_cast<T>(4)));
75 x = 1e-6f;
76 BOOST_CHECK_PREDICATE(::std::less_equal<T>(),
77 (acosh_error_evaluator(x))
78 (static_cast<T>(4)));
79 //
80 // Special cases:
81 //
82 if(std::numeric_limits<T>::has_infinity)
83 {
84 T inf = std::numeric_limits<T>::infinity();
85 boost::math::policies::policy<boost::math::policies::overflow_error<boost::math::policies::ignore_error> > pol;
86 BOOST_CHECK_EQUAL(boost::math::asinh(inf, pol), inf);
87 }
88 }
89
90
91 void acosh_manual_check()
92 {
93 BOOST_TEST_MESSAGE(" ");
94 BOOST_TEST_MESSAGE("acosh");
95
96 for (int i = 0; i <= 100; i++)
97 {
98 float xf = static_cast<float>(i-50)/static_cast<float>(5);
99 double xd = static_cast<double>(i-50)/static_cast<double>(5);
100 long double xl =
101 static_cast<long double>(i-50)/static_cast<long double>(5);
102
103 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
104 BOOST_TEST_MESSAGE( ::std::setw(15)
105 << acosh_error_evaluator(xf)
106 << ::std::setw(15)
107 << acosh_error_evaluator(xd)
108 << ::std::setw(15)
109 << acosh_error_evaluator(xl));
110 #else
111 BOOST_TEST_MESSAGE( ::std::setw(15)
112 << acosh_error_evaluator(xf)
113 << ::std::setw(15)
114 << acosh_error_evaluator(xd));
115 #endif
116 }
117
118 BOOST_TEST_MESSAGE(" ");
119 }
120