Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/math/special_functions/sinhc.hpp @ 16:2665513ce2d3
Add boost headers
author | Chris Cannam |
---|---|
date | Tue, 05 Aug 2014 11:11:38 +0100 |
parents | |
children | c530137014c0 |
comparison
equal
deleted
inserted
replaced
15:663ca0da4350 | 16:2665513ce2d3 |
---|---|
1 // boost sinhc.hpp header file | |
2 | |
3 // (C) Copyright Hubert Holin 2001. | |
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 // See http://www.boost.org for updates, documentation, and revision history. | |
9 | |
10 #ifndef BOOST_SINHC_HPP | |
11 #define BOOST_SINHC_HPP | |
12 | |
13 | |
14 #ifdef _MSC_VER | |
15 #pragma once | |
16 #endif | |
17 | |
18 #include <boost/math/tools/config.hpp> | |
19 #include <boost/math/tools/precision.hpp> | |
20 #include <boost/math/special_functions/math_fwd.hpp> | |
21 #include <boost/config/no_tr1/cmath.hpp> | |
22 #include <boost/limits.hpp> | |
23 #include <string> | |
24 #include <stdexcept> | |
25 | |
26 #include <boost/config.hpp> | |
27 | |
28 | |
29 // These are the the "Hyperbolic Sinus Cardinal" functions. | |
30 | |
31 namespace boost | |
32 { | |
33 namespace math | |
34 { | |
35 namespace detail | |
36 { | |
37 #if defined(__GNUC__) && (__GNUC__ < 3) | |
38 // gcc 2.x ignores function scope using declarations, | |
39 // put them in the scope of the enclosing namespace instead: | |
40 | |
41 using ::std::abs; | |
42 using ::std::sqrt; | |
43 using ::std::sinh; | |
44 | |
45 using ::std::numeric_limits; | |
46 #endif /* defined(__GNUC__) && (__GNUC__ < 3) */ | |
47 | |
48 // This is the "Hyperbolic Sinus Cardinal" of index Pi. | |
49 | |
50 template<typename T> | |
51 inline T sinhc_pi_imp(const T x) | |
52 { | |
53 #if defined(BOOST_NO_STDC_NAMESPACE) && !defined(__SUNPRO_CC) | |
54 using ::abs; | |
55 using ::sinh; | |
56 using ::sqrt; | |
57 #else /* BOOST_NO_STDC_NAMESPACE */ | |
58 using ::std::abs; | |
59 using ::std::sinh; | |
60 using ::std::sqrt; | |
61 #endif /* BOOST_NO_STDC_NAMESPACE */ | |
62 | |
63 static T const taylor_0_bound = tools::epsilon<T>(); | |
64 static T const taylor_2_bound = sqrt(taylor_0_bound); | |
65 static T const taylor_n_bound = sqrt(taylor_2_bound); | |
66 | |
67 if (abs(x) >= taylor_n_bound) | |
68 { | |
69 return(sinh(x)/x); | |
70 } | |
71 else | |
72 { | |
73 // approximation by taylor series in x at 0 up to order 0 | |
74 T result = static_cast<T>(1); | |
75 | |
76 if (abs(x) >= taylor_0_bound) | |
77 { | |
78 T x2 = x*x; | |
79 | |
80 // approximation by taylor series in x at 0 up to order 2 | |
81 result += x2/static_cast<T>(6); | |
82 | |
83 if (abs(x) >= taylor_2_bound) | |
84 { | |
85 // approximation by taylor series in x at 0 up to order 4 | |
86 result += (x2*x2)/static_cast<T>(120); | |
87 } | |
88 } | |
89 | |
90 return(result); | |
91 } | |
92 } | |
93 | |
94 } // namespace detail | |
95 | |
96 template <class T> | |
97 inline typename tools::promote_args<T>::type sinhc_pi(T x) | |
98 { | |
99 typedef typename tools::promote_args<T>::type result_type; | |
100 return detail::sinhc_pi_imp(static_cast<result_type>(x)); | |
101 } | |
102 | |
103 template <class T, class Policy> | |
104 inline typename tools::promote_args<T>::type sinhc_pi(T x, const Policy&) | |
105 { | |
106 return boost::math::sinhc_pi(x); | |
107 } | |
108 | |
109 #ifdef BOOST_NO_TEMPLATE_TEMPLATES | |
110 #else /* BOOST_NO_TEMPLATE_TEMPLATES */ | |
111 template<typename T, template<typename> class U> | |
112 inline U<T> sinhc_pi(const U<T> x) | |
113 { | |
114 #if defined(BOOST_FUNCTION_SCOPE_USING_DECLARATION_BREAKS_ADL) || defined(__GNUC__) | |
115 using namespace std; | |
116 #elif defined(BOOST_NO_STDC_NAMESPACE) && !defined(__SUNPRO_CC) | |
117 using ::abs; | |
118 using ::sinh; | |
119 using ::sqrt; | |
120 #else /* BOOST_NO_STDC_NAMESPACE */ | |
121 using ::std::abs; | |
122 using ::std::sinh; | |
123 using ::std::sqrt; | |
124 #endif /* BOOST_NO_STDC_NAMESPACE */ | |
125 | |
126 using ::std::numeric_limits; | |
127 | |
128 static T const taylor_0_bound = tools::epsilon<T>(); | |
129 static T const taylor_2_bound = sqrt(taylor_0_bound); | |
130 static T const taylor_n_bound = sqrt(taylor_2_bound); | |
131 | |
132 if (abs(x) >= taylor_n_bound) | |
133 { | |
134 return(sinh(x)/x); | |
135 } | |
136 else | |
137 { | |
138 // approximation by taylor series in x at 0 up to order 0 | |
139 #ifdef __MWERKS__ | |
140 U<T> result = static_cast<U<T> >(1); | |
141 #else | |
142 U<T> result = U<T>(1); | |
143 #endif | |
144 | |
145 if (abs(x) >= taylor_0_bound) | |
146 { | |
147 U<T> x2 = x*x; | |
148 | |
149 // approximation by taylor series in x at 0 up to order 2 | |
150 result += x2/static_cast<T>(6); | |
151 | |
152 if (abs(x) >= taylor_2_bound) | |
153 { | |
154 // approximation by taylor series in x at 0 up to order 4 | |
155 result += (x2*x2)/static_cast<T>(120); | |
156 } | |
157 } | |
158 | |
159 return(result); | |
160 } | |
161 } | |
162 #endif /* BOOST_NO_TEMPLATE_TEMPLATES */ | |
163 } | |
164 } | |
165 | |
166 #endif /* BOOST_SINHC_HPP */ | |
167 |