1 // boost sinhc.hpp header file
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)
8 // See http://www.boost.org for updates, documentation, and revision history.
10 #ifndef BOOST_SINHC_HPP
11 #define BOOST_SINHC_HPP
15 #include <boost/limits.hpp>
20 #include <boost/config.hpp>
23 // These are the the "Hyperbolic Sinus Cardinal" functions.
29 #if defined(__GNUC__) && (__GNUC__ < 3)
30 // gcc 2.x ignores function scope using declarations,
31 // put them in the scope of the enclosing namespace instead:
37 using ::std::numeric_limits;
38 #endif /* defined(__GNUC__) && (__GNUC__ < 3) */
40 // This is the "Hyperbolic Sinus Cardinal" of index Pi.
43 inline T sinhc_pi(const T x)
45 #ifdef BOOST_NO_STDC_NAMESPACE
49 #else /* BOOST_NO_STDC_NAMESPACE */
53 #endif /* BOOST_NO_STDC_NAMESPACE */
55 using ::std::numeric_limits;
57 static T const taylor_0_bound = numeric_limits<T>::epsilon();
58 static T const taylor_2_bound = sqrt(taylor_0_bound);
59 static T const taylor_n_bound = sqrt(taylor_2_bound);
61 if (abs(x) >= taylor_n_bound)
67 // approximation by taylor series in x at 0 up to order 0
68 T result = static_cast<T>(1);
70 if (abs(x) >= taylor_0_bound)
74 // approximation by taylor series in x at 0 up to order 2
75 result += x2/static_cast<T>(6);
77 if (abs(x) >= taylor_2_bound)
79 // approximation by taylor series in x at 0 up to order 4
80 result += (x2*x2)/static_cast<T>(120);
89 #ifdef BOOST_NO_TEMPLATE_TEMPLATES
90 #else /* BOOST_NO_TEMPLATE_TEMPLATES */
91 template<typename T, template<typename> class U>
92 inline U<T> sinhc_pi(const U<T> x)
94 #if defined(BOOST_FUNCTION_SCOPE_USING_DECLARATION_BREAKS_ADL) || defined(__GNUC__)
96 #elif defined(BOOST_NO_STDC_NAMESPACE)
100 #else /* BOOST_NO_STDC_NAMESPACE */
104 #endif /* BOOST_NO_STDC_NAMESPACE */
106 using ::std::numeric_limits;
108 static T const taylor_0_bound = numeric_limits<T>::epsilon();
109 static T const taylor_2_bound = sqrt(taylor_0_bound);
110 static T const taylor_n_bound = sqrt(taylor_2_bound);
112 if (abs(x) >= taylor_n_bound)
118 // approximation by taylor series in x at 0 up to order 0
120 U<T> result = static_cast<U<T> >(1);
122 U<T> result = U<T>(1);
125 if (abs(x) >= taylor_0_bound)
129 // approximation by taylor series in x at 0 up to order 2
130 result += x2/static_cast<T>(6);
132 if (abs(x) >= taylor_2_bound)
134 // approximation by taylor series in x at 0 up to order 4
135 result += (x2*x2)/static_cast<T>(120);
142 #endif /* BOOST_NO_TEMPLATE_TEMPLATES */
146 #endif /* BOOST_SINHC_HPP */