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 // This is the "Hyperbolic Sinus Cardinal" of index Pi.
40 inline T sinhc_pi_imp(const T x)
42 #if defined(BOOST_NO_STDC_NAMESPACE) && !defined(__SUNPRO_CC)
46 #else /* BOOST_NO_STDC_NAMESPACE */
50 #endif /* BOOST_NO_STDC_NAMESPACE */
52 static T const taylor_0_bound = tools::epsilon<T>();
53 static T const taylor_2_bound = sqrt(taylor_0_bound);
54 static T const taylor_n_bound = sqrt(taylor_2_bound);
56 if (abs(x) >= taylor_n_bound)
62 // approximation by taylor series in x at 0 up to order 0
63 T result = static_cast<T>(1);
65 if (abs(x) >= taylor_0_bound)
69 // approximation by taylor series in x at 0 up to order 2
70 result += x2/static_cast<T>(6);
72 if (abs(x) >= taylor_2_bound)
74 // approximation by taylor series in x at 0 up to order 4
75 result += (x2*x2)/static_cast<T>(120);
86 inline typename tools::promote_args<T>::type sinhc_pi(T x)
88 typedef typename tools::promote_args<T>::type result_type;
89 return detail::sinhc_pi_imp(static_cast<result_type>(x));
92 template <class T, class Policy>
93 inline typename tools::promote_args<T>::type sinhc_pi(T x, const Policy&)
95 return boost::math::sinhc_pi(x);
98 #ifdef BOOST_NO_TEMPLATE_TEMPLATES
99 #else /* BOOST_NO_TEMPLATE_TEMPLATES */
100 template<typename T, template<typename> class U>
101 inline U<T> sinhc_pi(const U<T> x)
103 #if defined(BOOST_FUNCTION_SCOPE_USING_DECLARATION_BREAKS_ADL) || defined(__GNUC__)
105 #elif defined(BOOST_NO_STDC_NAMESPACE) && !defined(__SUNPRO_CC)
109 #else /* BOOST_NO_STDC_NAMESPACE */
113 #endif /* BOOST_NO_STDC_NAMESPACE */
115 using ::std::numeric_limits;
117 static T const taylor_0_bound = tools::epsilon<T>();
118 static T const taylor_2_bound = sqrt(taylor_0_bound);
119 static T const taylor_n_bound = sqrt(taylor_2_bound);
121 if (abs(x) >= taylor_n_bound)
127 // approximation by taylor series in x at 0 up to order 0
129 U<T> result = static_cast<U<T> >(1);
131 U<T> result = U<T>(1);
134 if (abs(x) >= taylor_0_bound)
138 // approximation by taylor series in x at 0 up to order 2
139 result += x2/static_cast<T>(6);
141 if (abs(x) >= taylor_2_bound)
143 // approximation by taylor series in x at 0 up to order 4
144 result += (x2*x2)/static_cast<T>(120);
151 #endif /* BOOST_NO_TEMPLATE_TEMPLATES */
155 #endif /* BOOST_SINHC_HPP */