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>
27 // These are the the "Sinus Cardinal" functions.
35 // This is the "Sinus Cardinal" of index Pi.
38 inline T sinc_pi_imp(const T x)
42 if (abs(x) >= 3.3 * tools::forth_root_epsilon<T>())
48 // |x| < (eps*120)^(1/4)
56 inline typename tools::promote_args<T>::type sinc_pi(T x)
58 typedef typename tools::promote_args<T>::type result_type;
59 return detail::sinc_pi_imp(static_cast<result_type>(x));
62 template <class T, class Policy>
63 inline typename tools::promote_args<T>::type sinc_pi(T x, const Policy&)
65 typedef typename tools::promote_args<T>::type result_type;
66 return detail::sinc_pi_imp(static_cast<result_type>(x));
69 template<typename T, template<typename> class U>
70 inline U<T> sinc_pi(const U<T> x)
73 using ::std::numeric_limits;
75 T const taylor_0_bound = tools::epsilon<T>();
76 T const taylor_2_bound = tools::root_epsilon<T>();
77 T const taylor_n_bound = tools::forth_root_epsilon<T>();
79 if (abs(x) >= taylor_n_bound)
85 // approximation by taylor series in x at 0 up to order 0
87 U<T> result = static_cast<U<T> >(1);
89 U<T> result = U<T>(1);
92 if (abs(x) >= taylor_0_bound)
96 // approximation by taylor series in x at 0 up to order 2
97 result -= x2/static_cast<T>(6);
99 if (abs(x) >= taylor_2_bound)
101 // approximation by taylor series in x at 0 up to order 4
102 result += (x2*x2)/static_cast<T>(120);
110 template<typename T, template<typename> class U, class Policy>
111 inline U<T> sinc_pi(const U<T> x, const Policy&)
118 #endif /* BOOST_SINC_HPP */