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 T const taylor_0_bound = tools::epsilon<T>();
47 T const taylor_2_bound = tools::root_epsilon<T>();
48 T const taylor_n_bound = tools::forth_root_epsilon<T>();
50 if (abs(x) >= taylor_n_bound)
56 // approximation by taylor series in x at 0 up to order 0
57 T result = static_cast<T>(1);
59 if (abs(x) >= taylor_0_bound)
63 // approximation by taylor series in x at 0 up to order 2
64 result -= x2/static_cast<T>(6);
66 if (abs(x) >= taylor_2_bound)
68 // approximation by taylor series in x at 0 up to order 4
69 result += (x2*x2)/static_cast<T>(120);
80 inline typename tools::promote_args<T>::type sinc_pi(T x)
82 typedef typename tools::promote_args<T>::type result_type;
83 return detail::sinc_pi_imp(static_cast<result_type>(x));
86 template <class T, class Policy>
87 inline typename tools::promote_args<T>::type sinc_pi(T x, const Policy&)
89 typedef typename tools::promote_args<T>::type result_type;
90 return detail::sinc_pi_imp(static_cast<result_type>(x));
93 #ifndef BOOST_NO_TEMPLATE_TEMPLATES
94 template<typename T, template<typename> class U>
95 inline U<T> sinc_pi(const U<T> x)
98 using ::std::numeric_limits;
100 T const taylor_0_bound = tools::epsilon<T>();
101 T const taylor_2_bound = tools::root_epsilon<T>();
102 T const taylor_n_bound = tools::forth_root_epsilon<T>();
104 if (abs(x) >= taylor_n_bound)
110 // approximation by taylor series in x at 0 up to order 0
112 U<T> result = static_cast<U<T> >(1);
114 U<T> result = U<T>(1);
117 if (abs(x) >= taylor_0_bound)
121 // approximation by taylor series in x at 0 up to order 2
122 result -= x2/static_cast<T>(6);
124 if (abs(x) >= taylor_2_bound)
126 // approximation by taylor series in x at 0 up to order 4
127 result += (x2*x2)/static_cast<T>(120);
135 template<typename T, template<typename> class U, class Policy>
136 inline U<T> sinc_pi(const U<T> x, const Policy&)
140 #endif /* BOOST_NO_TEMPLATE_TEMPLATES */
144 #endif /* BOOST_SINC_HPP */