File indexing completed on 2025-01-18 09:40:23
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_SINC_HPP
0011 #define BOOST_SINC_HPP
0012
0013
0014 #ifdef _MSC_VER
0015 #pragma once
0016 #endif
0017
0018 #include <boost/math/tools/config.hpp>
0019 #include <boost/math/tools/precision.hpp>
0020 #include <boost/math/policies/policy.hpp>
0021 #include <boost/math/special_functions/math_fwd.hpp>
0022 #include <limits>
0023 #include <string>
0024 #include <stdexcept>
0025 #include <cmath>
0026
0027
0028
0029 namespace boost
0030 {
0031 namespace math
0032 {
0033 namespace detail
0034 {
0035
0036
0037 template<typename T>
0038 inline T sinc_pi_imp(const T x)
0039 {
0040 BOOST_MATH_STD_USING
0041
0042 if (abs(x) >= 3.3 * tools::forth_root_epsilon<T>())
0043 {
0044 return(sin(x)/x);
0045 }
0046 else
0047 {
0048
0049 return 1 - x * x / 6;
0050 }
0051 }
0052
0053 }
0054
0055 template <class T>
0056 inline typename tools::promote_args<T>::type sinc_pi(T x)
0057 {
0058 typedef typename tools::promote_args<T>::type result_type;
0059 return detail::sinc_pi_imp(static_cast<result_type>(x));
0060 }
0061
0062 template <class T, class Policy>
0063 inline typename tools::promote_args<T>::type sinc_pi(T x, const Policy&)
0064 {
0065 typedef typename tools::promote_args<T>::type result_type;
0066 return detail::sinc_pi_imp(static_cast<result_type>(x));
0067 }
0068
0069 template<typename T, template<typename> class U>
0070 inline U<T> sinc_pi(const U<T> x)
0071 {
0072 BOOST_MATH_STD_USING
0073 using ::std::numeric_limits;
0074
0075 T const taylor_0_bound = tools::epsilon<T>();
0076 T const taylor_2_bound = tools::root_epsilon<T>();
0077 T const taylor_n_bound = tools::forth_root_epsilon<T>();
0078
0079 if (abs(x) >= taylor_n_bound)
0080 {
0081 return(sin(x)/x);
0082 }
0083 else
0084 {
0085
0086 #ifdef __MWERKS__
0087 U<T> result = static_cast<U<T> >(1);
0088 #else
0089 U<T> result = U<T>(1);
0090 #endif
0091
0092 if (abs(x) >= taylor_0_bound)
0093 {
0094 U<T> x2 = x*x;
0095
0096
0097 result -= x2/static_cast<T>(6);
0098
0099 if (abs(x) >= taylor_2_bound)
0100 {
0101
0102 result += (x2*x2)/static_cast<T>(120);
0103 }
0104 }
0105
0106 return(result);
0107 }
0108 }
0109
0110 template<typename T, template<typename> class U, class Policy>
0111 inline U<T> sinc_pi(const U<T> x, const Policy&)
0112 {
0113 return sinc_pi(x);
0114 }
0115 }
0116 }
0117
0118 #endif
0119