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
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>
26 #include <boost/config.hpp>
29 // These are the the "Hyperbolic Sinus Cardinal" functions.
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:
45 using ::std::numeric_limits;
46 #endif /* defined(__GNUC__) && (__GNUC__ < 3) */
48 // This is the "Hyperbolic Sinus Cardinal" of index Pi.
51 inline T sinhc_pi_imp(const T x)
53 #if defined(BOOST_NO_STDC_NAMESPACE) && !defined(__SUNPRO_CC)
57 #else /* BOOST_NO_STDC_NAMESPACE */
61 #endif /* BOOST_NO_STDC_NAMESPACE */
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);
67 if (abs(x) >= taylor_n_bound)
73 // approximation by taylor series in x at 0 up to order 0
74 T result = static_cast<T>(1);
76 if (abs(x) >= taylor_0_bound)
80 // approximation by taylor series in x at 0 up to order 2
81 result += x2/static_cast<T>(6);
83 if (abs(x) >= taylor_2_bound)
85 // approximation by taylor series in x at 0 up to order 4
86 result += (x2*x2)/static_cast<T>(120);
97 inline typename tools::promote_args<T>::type sinhc_pi(T x)
99 typedef typename tools::promote_args<T>::type result_type;
100 return detail::sinhc_pi_imp(static_cast<result_type>(x));
103 template <class T, class Policy>
104 inline typename tools::promote_args<T>::type sinhc_pi(T x, const Policy&)
106 return boost::math::sinhc_pi(x);
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)
114 #if defined(BOOST_FUNCTION_SCOPE_USING_DECLARATION_BREAKS_ADL) || defined(__GNUC__)
116 #elif defined(BOOST_NO_STDC_NAMESPACE) && !defined(__SUNPRO_CC)
120 #else /* BOOST_NO_STDC_NAMESPACE */
124 #endif /* BOOST_NO_STDC_NAMESPACE */
126 using ::std::numeric_limits;
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);
132 if (abs(x) >= taylor_n_bound)
138 // approximation by taylor series in x at 0 up to order 0
140 U<T> result = static_cast<U<T> >(1);
142 U<T> result = U<T>(1);
145 if (abs(x) >= taylor_0_bound)
149 // approximation by taylor series in x at 0 up to order 2
150 result += x2/static_cast<T>(6);
152 if (abs(x) >= taylor_2_bound)
154 // approximation by taylor series in x at 0 up to order 4
155 result += (x2*x2)/static_cast<T>(120);
162 #endif /* BOOST_NO_TEMPLATE_TEMPLATES */
166 #endif /* BOOST_SINHC_HPP */