1 // boost sinc.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_SINC_HPP
11 #define BOOST_SINC_HPP
18 #include <boost/math/tools/config.hpp>
19 #include <boost/math/tools/precision.hpp>
20 #include <boost/math/policies/policy.hpp>
21 #include <boost/math/special_functions/math_fwd.hpp>
22 #include <boost/config/no_tr1/cmath.hpp>
23 #include <boost/limits.hpp>
28 #include <boost/config.hpp>
31 // These are the the "Sinus Cardinal" functions.
39 // This is the "Sinus Cardinal" of index Pi.
42 inline T sinc_pi_imp(const T x)
46 if (abs(x) >= 3.3 * tools::forth_root_epsilon<T>())
52 // |x| < (eps*120)^(1/4)
60 inline typename tools::promote_args<T>::type sinc_pi(T x)
62 typedef typename tools::promote_args<T>::type result_type;
63 return detail::sinc_pi_imp(static_cast<result_type>(x));
66 template <class T, class Policy>
67 inline typename tools::promote_args<T>::type sinc_pi(T x, const Policy&)
69 typedef typename tools::promote_args<T>::type result_type;
70 return detail::sinc_pi_imp(static_cast<result_type>(x));
73 #ifndef BOOST_NO_TEMPLATE_TEMPLATES
74 template<typename T, template<typename> class U>
75 inline U<T> sinc_pi(const U<T> x)
78 using ::std::numeric_limits;
80 T const taylor_0_bound = tools::epsilon<T>();
81 T const taylor_2_bound = tools::root_epsilon<T>();
82 T const taylor_n_bound = tools::forth_root_epsilon<T>();
84 if (abs(x) >= taylor_n_bound)
90 // approximation by taylor series in x at 0 up to order 0
92 U<T> result = static_cast<U<T> >(1);
94 U<T> result = U<T>(1);
97 if (abs(x) >= taylor_0_bound)
101 // approximation by taylor series in x at 0 up to order 2
102 result -= x2/static_cast<T>(6);
104 if (abs(x) >= taylor_2_bound)
106 // approximation by taylor series in x at 0 up to order 4
107 result += (x2*x2)/static_cast<T>(120);
115 template<typename T, template<typename> class U, class Policy>
116 inline U<T> sinc_pi(const U<T> x, const Policy&)
120 #endif /* BOOST_NO_TEMPLATE_TEMPLATES */
124 #endif /* BOOST_SINC_HPP */